c# - enable and disable asp validator using embedded code in asp tag dosent work -


enable , disable asp validator using embedded code in asp tag doesn't work, value written control still enabled. please check occurrences of

enabled="<%# convert.toboolean(txttext.enabled) ? false : true%>"  

in form:

<form id="frmvalidator" runat="server">     <div>         <asp:validationsummary             id="summary"             runat="server"             headertext="error(s):"             cssclass="msg-error" />         <asp:textbox id="txttext" runat="server" maxlength="15" enabled="false" />         <asp:requiredfieldvalidator             id="rfvtxttext"             runat="server"             controltovalidate="txttext"             errormessage="requiered."             display="none"             clientvalidationfunction=""             setfocusonerror="true"             enabled="<%# convert.toboolean(txttext.enabled) ? false : true%>" />          <asp:regularexpressionvalidator             id="revtxttext"             runat="server"             controltovalidate="txttext"             display="none"             errormessage="invalid."             validationexpression="[a-za-zñÑáéíóúÁÉÍÓÚ ,.*]{3,50}"             setfocusonerror="true"             enabled="<%# convert.toboolean(txttext.enabled) ? false : true%>" />          <asp:button             id="btnsave"             runat="server"             text="save" />     </div> <form> 

the answer cannot.

<%# %> data binding expression syntax. cannot use without servercontrol such gridview, listview.

normally, disable/enable control code behind.

javascript method

another approach disable validation using javascript. however, need redirect different page or after button click. otherwise, validation message displayed user after post back.

<script type="text/javascript">     if (document.getelementbyid('<%= txttext.clientid %>').getattribute('disabled') === 'disabled') {         alert('disabled');         validatorenable(document.getelementbyid('<%= rfvtxttext.clientid %>'), false);         validatorenable(document.getelementbyid('<%= revtxttext.clientid %>'), false);     } </script> 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -