1

I want to disable required validator field for a specific button click which is not check only a textbox. i've tried this code in the button click but not worked. so need this type of code how solve.

protected void Button3_Click(object sender, EventArgs e)
{
     if (TextBox1 == null)
    {
        RequiredFieldValidator1.EnableViewState = false;
    }
}
5
  • EnableViewState has nothing to do with validation and TextBox1 == null will never be true if it exists Commented May 13, 2016 at 7:46
  • how can i done this? need an idea Commented May 13, 2016 at 8:28
  • Use ValidatorGroups, this button gets a different group than the RequiredFieldValidator, voila. Commented May 13, 2016 at 8:29
  • do you have any link validatorGroup code? plz share@TimSchmelter Commented May 13, 2016 at 8:43
  • Have you clicked at the link i've provided in my last comment? Commented May 13, 2016 at 8:51

2 Answers 2

1

Just set CausesValidation="false" on your button property.

If you wish to validate that particular button with some other TextBox or control you can set ValidationGroup="groupA" to those controls and name it same group.

Sign up to request clarification or add additional context in comments.

4 Comments

which code will set in the groupA. is it need to js@mer hardik
no you can set on each controls that needs validation and leave out of group for those controls where you don't want to apply validation. or you can just CausesValidation="false" on your button and it will not trigger validation
done by added a label . and with a if condition. my requirement was disable validator for only a button. thnx @mer hardik
great to hear that :)
0

RequiredFieldValidator61.Visible = false; is what worked for me. It disables the error massage.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.