我在用户控件中有一个 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">
</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>
内部用户控件的 Page_Load 中没有任何内容,它是通过调用设置 InvoiceId 和 PopulateGrid 从外部初始化的。