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

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

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>

Comments:1

Leave a Reply
  1. Reply admin 12/05/18

    Page.IsValid would be false on the server side so you have two options here;

    1. Either remove Page.IsValid on Save button (which is not a good option)
    2. Good option is; check the same client logic on the server side before Page.IsValid and disable the validators from the server side then your Page.IsValid would give you true.

    Shoaib

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

TOP