1

我在用户控件中有一个 DropDownList,它本身就在用户控件中。

我遇到的问题是,当有人从 DDL 中选择一个项目时,我需要触发回发,以便我可以更新内部用户控件上的一些文本框。

但是如果我使用自动回发,我会收到一个 JS 错误“无法将焦点移动到控件,因为它是不可见的、未启用的或不接受焦点的类型。”

有人对此有任何想法吗?让我发疯...

       <asp:MultiView ID="mvInvoiceItem" runat="server" ActiveViewIndex="0">
        <asp:View ID="vwInvoiceItemList" runat="server">
            <asp:LinkButton ID="btn_AddInvoiceItem" runat="server" 
                onclick="btn_AddInvoiceItem_Click">Add Part</asp:LinkButton>
            <asp:GridView ID="gvwInvoiceItems" runat="server" AutoGenerateColumns="False" 
                EnableModelValidation="True" 
                OnRowCommand="gvwInvoiceItems_RowCommand"
                DataKeyNames="Id" 
                AllowPaging="True" Width="750px" PageSize="3" >
                <Columns>
                    <asp:BoundField DataField="Id" HeaderText="1" itemstyle-cssclass="invisibleColumn" >
                        <HeaderStyle CssClass="invisibleColumn" />
                        <ItemStyle CssClass="invisibleColumn" />
                    </asp:BoundField>
                    <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                    <asp:BoundField DataField="Quantity" HeaderText="Quantity" SortExpression="Quantity" />
                    <asp:BoundField DataField="IsSupplied" HeaderText="IsSupplied" SortExpression="IsSupplied" />
                    <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
                    <asp:BoundField DataField="Cost" HeaderText="Cost" SortExpression="Cost" />
                    <asp:ButtonField ButtonType="Image" ImageUrl="~/Images/btn_select.png" CommandName="SelectRow" Text="Select" />
                    <asp:ButtonField ButtonType="Image" ImageUrl="~/Images/btn_remove.png" CommandName="RemoveRow" Text="Remove" />
                </Columns>
            </asp:GridView>
        </asp:View>
        <asp:View ID="vwInvoiceItemEdit" runat="server">
            <table>
                <tr>
                    <td class="style2">
                        <asp:Label ID="lbl_InvoiceItem" runat="server" 
                            Text="Part.."></asp:Label>
                    </td>
                    <td>
                        <asp:DropDownList ID="dd_InvoiceItem" runat="server" 
                            DataTextField="Name" DataValueField="Id" Width="215px" AutoPostBack="true"
                            OnSelectedIndexChanged="dd_InvoiceItem_SelectedIndexChanged">
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td class="style2">
                        <asp:Label ID="lbl_InvoiceItemQuantity" runat="server" Text="Quantity.."></asp:Label>
                    </td>
                    <td width="250px">
                        <asp:TextBox ID="txt_InvoiceItemQuantity" runat="server" MaxLength="100" 
                            Width="190px" autocomplete="off"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td class="style2">
                        <asp:Label ID="lbl_InvoiceItemPrice" runat="server" Text="Price.."></asp:Label>
                    </td>
                    <td width="250px">
                        <asp:TextBox ID="txt_InvoiceItemPrice" runat="server" MaxLength="100" 
                            Width="190px" autocomplete="off"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td class="style2">
                        <asp:Label ID="lbl_InvoiceItemIsSupplied" runat="server" Text="Supplied.."></asp:Label>
                    </td>
                    <td>
                        <asp:CheckBox ID="chk_InvoiceItemIsSupplied" runat="server"/>
                    </td>
                </tr>
                <tr>
                    <td class="style2">
                        <asp:Label ID="lbl_InvoiceItemCost" runat="server" Text="Cost.."></asp:Label>
                    </td>
                    <td width="250px">
                        <asp:TextBox ID="txt_InvoiceItemCost" runat="server" MaxLength="100" 
                            Width="190px" autocomplete="off"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td class="style2">
                        &nbsp;</td>
                    <td align="right">
                        <asp:ImageButton ID="btn_InvoiceItemSave" runat="server" 
                            ImageUrl="~/Images/btn_save.png" onclick="btn_InvoiceItemSave_Click" />
                        &nbsp;<asp:ImageButton ID="btn_InvoiceItemCancel" runat="server" 
                            ImageUrl="~/Images/btn_cancel.png" onclick="btn_InvoiceItemCancel_Click" CausesValidation="false" />
                    </td>
                </tr>
            </table>
        </asp:View>
    </asp:MultiView>

内部用户控件的 Page_Load 中没有任何内容,它是通过调用设置 InvoiceId 和 PopulateGrid 从外部初始化的。

4

1 回答 1

2

这很奇怪。经过进一步调查,我发现有人已经针对焦点问题实施了此解决方案http://couldbedone.blogspot.com/2007/08/restoring-lost-focus-in-update-panel.html

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    <Scripts>
        <asp:ScriptReference Path="~/Resources/Focus.js" />
    </Scripts>
</asp:ToolkitScriptManager>

我的问题的解决方案是从托管 ASPX 页面上的 ScriptManager 中删除对此 JS 的引用。

于 2011-12-22T09:29:51.650 回答