DropDownList 回发问题

发布于 2024-12-22 05:07:14 字数 5567 浏览 1 评论 0原文

我在用户控件内有一个 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 从外部初始化的。

I have a DropDownList inside a usercontrol, which is itself inside a usercontrol.

The problem I have is that when someone selects an item from the DDL, I need to fire a postback so I can update some textbox's on the inner usercontrol.

But if I use autopostback, I get a JS error "Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus."

Anyone have any ideas on this? Driving me loopy...

       <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">
                         </td>
                    <td align="right">
                        <asp:ImageButton ID="btn_InvoiceItemSave" runat="server" 
                            ImageUrl="~/Images/btn_save.png" onclick="btn_InvoiceItemSave_Click" />
                         <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>

There is nothing in the Page_Load for the inner usercontrol, it is initialised from the outside with calls to set the InvoiceId and PopulateGrid.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月亮邮递员 2024-12-29 05:07:14

这很奇怪。经过进一步调查,我发现有人已经针对焦点问题实施了此解决方案 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>

我的问题的解决方案是删除对此 JS 来自托管 ASPX 页面上的 ScriptManager。

This is quite odd. Upon further investigation I found that someone had implemented this solution to a focus issue 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>

The solution to my problem was removing the reference to this JS from the ScriptManager on the hosting ASPX page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文