Keep button from triggering validation

B

Brett Robichaud

I have a form with two buttons and a TextBox. If I use a Validation control
then both buttons trigger the validation, I only want one of them to trigger
it. Is there any way to keep one of the buttons from triggering validation?

For example, how can I keep the Cancel button from causing validation to
occur?

<asp:TextBox runat="server" ID="addComment" Columns="20" />
<asp:RequiredFieldValidator runat="server" id="reqField"
ControlToValidate="addComment" ErrorMessage="*" />
<asp:LinkButton runat="server" CommandName="Insert" id="btnAdd" Text="OK" />
<asp:LinkButton runat="server" CommandName="Cancel" id="btnCancel"
Text="Cancel" />

-Brett-
 
G

Guest

Set MyCancelButton.CausesValidation = fals

----- Brett Robichaud wrote: ----

I have a form with two buttons and a TextBox. If I use a Validation contro
then both buttons trigger the validation, I only want one of them to trigge
it. Is there any way to keep one of the buttons from triggering validation

For example, how can I keep the Cancel button from causing validation t
occur

<asp:TextBox runat="server" ID="addComment" Columns="20" /><asp:RequiredFieldValidator runat="server" id="reqField
ControlToValidate="addComment" ErrorMessage="*" /><asp:LinkButton runat="server" CommandName="Insert" id="btnAdd" Text="OK" /><asp:LinkButton runat="server" CommandName="Cancel" id="btnCancel
Text="Cancel" /

-Brett
 
G

Guest

Set CausesValidation="False" for the button which you don't want to cause validation when you click it

----- Brett Robichaud wrote: ----

I have a form with two buttons and a TextBox. If I use a Validation contro
then both buttons trigger the validation, I only want one of them to trigge
it. Is there any way to keep one of the buttons from triggering validation

For example, how can I keep the Cancel button from causing validation t
occur

<asp:TextBox runat="server" ID="addComment" Columns="20" /><asp:RequiredFieldValidator runat="server" id="reqField
ControlToValidate="addComment" ErrorMessage="*" /><asp:LinkButton runat="server" CommandName="Insert" id="btnAdd" Text="OK" /><asp:LinkButton runat="server" CommandName="Cancel" id="btnCancel
Text="Cancel" /

-Brett
 
B

Brett Robichaud

Perfect. Why I didn't find that myself I have no idea...

Thanks!

-Brett-

Bill Borg said:
Set MyCancelButton.CausesValidation = false

----- Brett Robichaud wrote: -----

I have a form with two buttons and a TextBox. If I use a Validation control
then both buttons trigger the validation, I only want one of them to trigger
it. Is there any way to keep one of the buttons from triggering validation?

For example, how can I keep the Cancel button from causing validation to
occur?

<asp:TextBox runat="server" ID="addComment" Columns="20"
/><asp:RequiredFieldValidator runat="server" id="reqField"
ControlToValidate="addComment" ErrorMessage="*" /><asp:LinkButton
runat="server" CommandName="Insert" id="btnAdd" Text="OK" /><asp:LinkButton
runat="server" CommandName="Cancel" id="btnCancel"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top