c# - Enable/Disable Required field validator from cs page? -


i have 2 textbox , 2 buttons in page.

one hidden , other 1 displayed.

when click button1, save data of 2 textbox , validate each textbox requiredfieldvalidator.

then when click button2, hide (button2) , show hidden textbox.

both textbox has requiredfieldvalidator validating against button1's event click.

now issue when enter text 1st textbox , click save, button click validating required field hidden field. want validate 2 textbox when showing.

how can avoid this?

well can simple use enabled="false" property of requiredfieldvalidator.

your markup based on question.

<asp:textbox runat="server" id="tb1"></asp:textbox> <asp:requiredfieldvalidator runat="server" id="rfv1" controltovalidate="tb1" errormessage="*" validationgroup="gvsave"> </asp:requiredfieldvalidator>  <asp:textbox runat="server" id="tb2" visible="false"></asp:textbox> <asp:requiredfieldvalidator runat="server" id="rfv2" controltovalidate="tb2" errormessage="*" enabled="false" validationgroup="gvsave"> </asp:requiredfieldvalidator>  <asp:button runat="server" id="btn1" text="save" onclick="btn1_click" validationgroup="gvsave"/> <asp:button runat="server" id="btn2" text="show" onclick="btn2_click" /> 

and codebehind this:

protected void btn2_click(object sender, eventargs e) {     tb2.visible = true;     rfv2.enabled = true; // enables second requiredfieldvalidator }  protected void btn1_click(object sender, eventargs e) {   // saving code here } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -