[英]Selecting an asp.net control which is in an UpdatePanel
我想启用一个在ListView(ID =“ SehensList”)中的DropDownList并放入UpdatePanel中。 我的第一个赌注是以下,但没有奏效。
DropDownList DropdownDistrict = (DropDownList)SehenList.InsertItem.FindControl("DistrictDropDownListInsert");
DropdownDistrict.Enabled = true;
这是aspx面;
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
</td>
<td>
<asp:TextBox ID="CityFKTextBox_Insert" runat="server" Visible="false" Text='<%# Bind("CityFK") %>' />
<asp:DropDownList ID="CityFKDropDownListInsert" runat="server" DataSourceID="CityFKEntityDataSource_Insert" AutoPostBack="true"
OnSelectedIndexChanged="CityFKDropDownListInsert_SelectedIndexChanged" DataTextField="CityName" DataValueField="CityID"
AppendDataBoundItems="true">
<asp:ListItem Text="-Stadt Wählen-" Value="0" ></asp:ListItem>
</asp:DropDownList>
<asp:EntityDataSource ID="CityFKEntityDataSource_Insert" runat="server"
ConnectionString="name=MedicalEntities" DefaultContainerName="MedicalEntities"
EntitySetName="Cities">
</asp:EntityDataSource>
<asp:ScriptManager ID="SMCityFKInsert" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UPCityFKInsert" runat="server">
<ContentTemplate>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="CityFKDropDownListInsert" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</td>
<td>
<asp:TextBox ID="DistrictTextBox_Insert" runat="server" Visible="false" Text='<%# Bind("District") %>' />
<asp:DropDownList ID="DistrictDropDownListInsert" runat="server" Enabled="false" AutoPostBack="true"
OnSelectedIndexChanged="DistrictDropDownListInsert_SelectedIndexChanged" DataTextField="DistrictName" DataValueField="DistrictID"
AppendDataBoundItems="true">
<asp:ListItem Text="-Stadt Wählen-" Value="0" ></asp:ListItem>
</asp:DropDownList>
<asp:UpdatePanel ID="UPDistrictInsert" runat="server">
<ContentTemplate>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DistrictDropDownListInsert" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
</InsertItemTemplate>
如您所见,DropDownLists在UpdatePanel之外,并通过“触发器”调用。 如果我将DropDownLists放入UpdatePanel ContentTemplate中(我想这是完全错误的方法),则会启用第二个DropDownList“ DistrictDropDownListInsert”,但在这种情况下,不会多次更新。 我的意思是,如果更改第一个DropDownList“ CityFKDropDownListInsert”,则“不会多次更新”将其设置为其先前的值(不是默认值,而是第一个选定的值)。 我知道这有点令人困惑。 如果您有任何不清楚的部分,请告诉我。
应该是这样的:
protected void SehenList_ItemInserting(object sender, ListViewInsertEventArgs e)
{
var pnl = SehenList.InsertItem.FindControl("UPCityFKInsert") as UpdatePanel;
if (pnl != null)
{
var ddlDistrictInsert = pnl.FindControl("DistrictDropDownListInsert") as DropDownList;
if (ddlDistrictInsert != null) ddlDistrictInsert.Enabled = true;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.