如何在ASP中触发OnChange类型的事件.净c#
本文关键字:类型 事件 OnChange ASP | 更新日期: 2023-09-27 18:19:23
我有这个onchange事件在我的JS,根据选择列表,改变它下面的文本框的最大长度。现在我想能够做到这一点服务器端只是以防万一,如果用户有JS关闭。
我有一些代码背后的代码,但它只工作后的选择,然后页面刷新,我希望能够工作没有刷新因子或某种自动刷新,只要用户从下拉菜单中选择一个选项。
这是我的代码背后:-
protected void ListPayment_SelectedIndexChanged(object sender, EventArgs e)
{
if (ListPayment.SelectedIndex == 4)
{
TextBoxCCN.MaxLength = 15;
TextCSS.MaxLength = 4;
}
else if (ListPayment.SelectedIndex != 4)
{
TextBoxCCN.MaxLength = 16;
TextCSS.MaxLength = 3;
}
}
这是我的HTML
<asp:DropDownList ID="ListPayment" runat="server"
onchange="ValidateCCN();"
OnSelectedIndexChanged="ListPayment_SelectedIndexChanged">
<asp:ListItem Value="0">Select...</asp:ListItem>
<asp:ListItem Value="Visa">Visa</asp:ListItem>
<asp:ListItem Value="MasterCard">MasterCard</asp:ListItem>
<asp:ListItem Value="Discover">Discover</asp:ListItem>
<asp:ListItem Value="American Express">American Express</asp:ListItem>
</asp:DropDownList>
这是AutoPostBack
属性的作用:
<asp:DropDownList AutoPostBack="true"...
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.autopostback (v = vs.110) . aspx
<标题>编辑:完整修订代码:
<asp:DropDownList ID="ListPayment" runat="server" AutoPostBack="true"
onchange="ValidateCCN();"
OnSelectedIndexChanged="ListPayment_SelectedIndexChanged">
<asp:ListItem Value="0">Select...</asp:ListItem>
<asp:ListItem Value="Visa">Visa</asp:ListItem>
<asp:ListItem Value="MasterCard">MasterCard</asp:ListItem>
<asp:ListItem Value="Discover">Discover</asp:ListItem>
<asp:ListItem Value="American Express">American Express</asp:ListItem>
</asp:DropDownList>
标题>