C# 仅使用“来自”下拉框中的值刷新更新
我有一个名为“DropDownList1”的下拉列表。从下拉列表中选择的任何值都不能刷新页面,只能刷新面板。我的代码如下所示C# 仅使用“来自”下拉框中的值刷新更新,c#,asp.net,ajax,C#,Asp.net,Ajax,我有一个名为“DropDownList1”的下拉列表。从下拉列表中选择的任何值都不能刷新页面,只能刷新面板。我的代码如下所示 <asp:DropDownList ID="DropDownList1" runat="server" Width="200px" autopostback="true" OnSelectedIndexChanged="DropDownList1sel"> <asp:ListItem Text="abc" Value="0"></
<asp:DropDownList ID="DropDownList1" runat="server" Width="200px" autopostback="true" OnSelectedIndexChanged="DropDownList1sel">
<asp:ListItem Text="abc" Value="0"></asp:ListItem>
<asp:ListItem Text="a" Value="1"></asp:ListItem>
<asp:ListItem Text="b" Value="2"></asp:ListItem>
<asp:ListItem Text="c" Value="3"></asp:ListItem>
</asp:DropDownList>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
当我运行这段代码时,它必须调用ascx.cs中名为“DropDownList1sel”的函数,其中填充了“Label1”。现在页面被刷新,值被填充。我希望在不重新加载页面的情况下刷新面板。请帮忙 没什么事可做
设置UpdateMode=conditional,然后将触发器添加为DropDownList1
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="conditional" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1"
EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
为什么不在UpdatePanel中添加下拉列表呢
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" Width="200px"
AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_OnSelectedIndexChanged">
<asp:ListItem Text="abc" Value="0"></asp:ListItem>
<asp:ListItem Text="a" Value="1"></asp:ListItem>
<asp:ListItem Text="b" Value="2"></asp:ListItem>
<asp:ListItem Text="c" Value="3"></asp:ListItem>
</asp:DropDownList>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="DropDownList1"/>
</Triggers>
</asp:UpdatePanel>
您必须将该面板放置在更新面板中
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<panel id="panel1">
</panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" />
</Triggers>
</asp:UpdatePanel>
您试用了哪些代码?请用代码编辑您的原始问题。向我们展示ascx.cs代码的某些部分您是否找到了解决问题的合适方法?