【发布时间】:2014-08-26 19:37:16
【问题描述】:
我的 JS 中有这个 onchange 事件,它根据选择列表更改它下面的文本框的最大长度。现在我希望能够在服务器端执行此操作,以防万一用户关闭了 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>
【问题讨论】:
标签: c# asp.net code-behind