enable disable asp.net validators on drop down selection change client side

Filed in .Net 1 Comment

JavaScript function:

function setValidations() {

var ddlst = document.getElementById(“<%=ddlPiggyback.ClientID%>”);

var Text = ddlst.options[ddlst.selectedIndex].text;

if (Text == ’0′) {

ValidatorEnable(document.getElementById(“<%=rfvPiggybackComments.ClientID%>”), false);

}

else {

ValidatorEnable(document.getElementById(“<%=rfvPiggybackComments.ClientID%>”), true);

}

}

In drop down (aspx side)

<asp:DropDownList ID=”ddlPiggyback” runat=”server” onchange=”setValidations();”>

<asp:ListItem>0</asp:ListItem>

<asp:ListItem>1</asp:ListItem>

<asp:ListItem>2</asp:ListItem>

</asp:DropDownList>

TOP