C#EXT(奇怪的行为):ascx调用另一个ascx的directmethod

时间:2017-05-23 10:22:43

标签: c# extjs

在我的项目中,我有(以及其他)2 ascx个文件。每个人都有一个可编辑的网格。但是当我在UsersGrid.ascx文件的网格中编辑一个单元格时,它会调用TrialDashboard.ascx文件的直接方法。如果我发出一个带有此错误的alert(),问题就解决了:

  参数列表

之后的

Uncaught SyntaxError:missing)

在调用其直接方法之前,在TrialDashboard.ascx的edit()js函数中

。这是代码:

UsersGrid.ascx

<ext:XScript ID="XScript1" runat="server">
    <script type="text/javascript">
        var edit = function (editor, e) {
            if (!(e.value === e.originalValue)) //|| (Ext.isDate(e.value) && Ext.Date.isEqual(e.value, e.originalValue)))) {
               #{DirectMethods}.UpdateRow(e.record.data.UserId, e.field, e.originalValue, e.value);

        };

        var Before = function (item,e) {
            //alert('e.record.data.UserId:'+e.record.data.UserId+'e.field:'+e.field+'e.originalValue:'+e.originalValue+'e.value:'+e.value);
            if ((e.column.id === 'ColUsersNotes' || e.column.id === 'ColUsersAssessment') && e.record.get('Role') != 'Investigator')
            {
                return false;
            }
            return true;
        };
   </script>
</ext:XScript>

<ColumnModel runat="server" ID="UsersColumModel1" >
    <Columns>
       <ext:Column runat="server" ID="ColUsersEmail" DataIndex="Email" Text="Email"MinWidth="200"  Flex="2">
                                 <Editor>
                                       <ext:TextField runat="server" />
                                </Editor>
                            </ext:Column>
    </Columns>
</ColumnModel>
<SelectionModel>
           <ext:CellSelectionModel runat="server" />
            </SelectionModel>
                    <Plugins>
                        <ext:CellEditing runat="server">
                            <Listeners>
                                <BeforeEdit Handler="return Before(item, e);" />
                                <Edit Fn="edit" />
                            </Listeners>
                        </ext:CellEditing>
                    </Plugins>

TrialDashboard.ascx

<ext:XScript ID="XScript1" runat="server">
    <script type="text/javascript">
        var edit = function (editor, e) {
            alert( "TD:"+e.field+ e.originalValue+ e.value e.record.data); //if alert() is here then code works as expected

            if (!(e.value === e.originalValue)) //|| (Ext.isDate(e.value) && Ext.Date.isEqual(e.value, e.originalValue)))) {
            {
                #{DirectMethods}.UpdateRo(e.record.data.id, e.record.data.Siteid, e.field, e.originalValue, e.value);
            }//#{DirectMethods}.UpdateRow(e.record.data.Siteid, e.field, e.originalValue, e.value);

        };



    </script>
</ext:XScript>

1 个答案:

答案 0 :(得分:0)

edit函数定义了两次。即使它们位于单独的ascx文件中,如果名称在使用自定义控件的页面上不唯一,则会覆盖另一个。您可以尝试将它们重命名为UsersGrid_editTrialDashboard_edit,或使用其他命名约定来确保名称唯一。

<强> UsersGrid.ascx

<ext:XScript ID="XScript1" runat="server">
    <script type="text/javascript">
        var UsersGrid_edit = function (editor, e) {
            if (!(e.value === e.originalValue)) //|| (Ext.isDate(e.value) && Ext.Date.isEqual(e.value, e.originalValue)))) {
               #{DirectMethods}.UpdateRow(e.record.data.UserId, e.field, e.originalValue, e.value);

        };

        var UsersGrid_Before = function (item,e) {
            //alert('e.record.data.UserId:'+e.record.data.UserId+'e.field:'+e.field+'e.originalValue:'+e.originalValue+'e.value:'+e.value);
            if ((e.column.id === 'ColUsersNotes' || e.column.id === 'ColUsersAssessment') && e.record.get('Role') != 'Investigator')
            {
                return false;
            }
            return true;
        };
   </script>
</ext:XScript>

<ColumnModel runat="server" ID="UsersColumModel1" >
    <Columns>
       <ext:Column runat="server" ID="ColUsersEmail" DataIndex="Email" Text="Email"MinWidth="200"  Flex="2">
                                 <Editor>
                                       <ext:TextField runat="server" />
                                </Editor>
                            </ext:Column>
    </Columns>
</ColumnModel>
<SelectionModel>
           <ext:CellSelectionModel runat="server" />
            </SelectionModel>
                    <Plugins>
                        <ext:CellEditing runat="server">
                            <Listeners>
                                <BeforeEdit Handler="return UsersGrid_Before(item, e);" />
                                <Edit Fn="UsersGrid_edit" />
                            </Listeners>
                        </ext:CellEditing>
                    </Plugins>

<强> TrialDashboard.ascx

<ext:XScript ID="XScript1" runat="server">
    <script type="text/javascript">
        var TrialDashboard_edit = function (editor, e) {
            alert( "TD:"+e.field+ e.originalValue+ e.value e.record.data); //if alert() is here then code works as expected

            if (!(e.value === e.originalValue)) //|| (Ext.isDate(e.value) && Ext.Date.isEqual(e.value, e.originalValue)))) {
            {
                #{DirectMethods}.UpdateRo(e.record.data.id, e.record.data.Siteid, e.field, e.originalValue, e.value);
            }//#{DirectMethods}.UpdateRow(e.record.data.Siteid, e.field, e.originalValue, e.value);

        };



    </script>
</ext:XScript>