I have this onchange event in my JS that according to a select list, changes the maxlength for the textboxes under it. Now i want to be able to do this server side just incase if a user has JS turned off.
I have some code behind code but it only works after the selection is made and then the page is refreshed, i want to be able to work without the refresh factor or some sort of auto refresh as soon as the user selects an option from the dropdown.
This is my Code Behind:-
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;
}
}
This is my 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>