c# – 在没有PostBack的情况下更改标签文本(使用更新面板)
发布时间:2020-12-15 18:31:19 所属栏目:百科 来源:网络整理
导读:我创建了一个ASP.NET网站. 我想要做的是根据下拉列表中选择的项目使标签更改其内容. 我尝试了这个,但它不起作用: 下拉列表如下所示: asp:DropDownList ID="DropDown1" runat="server" asp:ListItem Value="a"/asp:ListItem asp:ListItem Value="b"/asp:Lis
我创建了一个ASP.NET网站.
我想要做的是根据下拉列表中选择的项目使标签更改其内容. 我尝试了这个,但它不起作用: 下拉列表如下所示: <asp:DropDownList ID="DropDown1" runat="server" > <asp:ListItem Value="a"></asp:ListItem> <asp:ListItem Value="b"></asp:ListItem> onselectedindexchanged="DropDown1_SelectedIndexChanged" </asp:DropDownList> 标签: <asp:Label ID="Label1" Text="" runat="server"/> 我想这样做而不必使用PostBack. 我试图使用ajax Update面板像这样: <asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional"> <Triggers> <asp:AsyncPostBackTrigger controlid="DropDown1" EventName="SelectedIndexChanged" /> </Triggers> <ContentTemplate> <asp:Label ID="Label1" Text="" runat="server"/> </ContentTemplate> </asp:UpdatePanel> 并且在代码后面的DropDown1_SelectedIndexChanged事件中: protected void DropDown1_SelectedIndexChanged(object sender,EventArgs e) { Label1.Text = DropDown1.SelectedValue; } 但这不起作用. 任何人都可以帮助我吗? 非常感谢您的帮助 解决方法
这是你的解决方案..
用下面的一个替换你的下拉式aspx控件.. <asp:DropDownList ID="DropDown1" runat="server" onselectedindexchanged="DropDown1_SelectedIndexChanged" AutoPostBack="true"> <asp:ListItem Value="a"></asp:ListItem> <asp:ListItem Value="b"></asp:ListItem> </asp:DropDownList> <asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional"> <ContentTemplate> <asp:Label ID="Label1" Text="test" runat="server"/> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger controlid="DropDown1" EventName="SelectedIndexChanged" /> </Triggers> </asp:UpdatePanel> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |