• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

Miss the RequiredFieldValidator checking

Syntax

The RequiredFieldValidator will check when I submit a form by "Submit" button. But if I click "Cancel" button, which also warning me by RequiredFieldValidator cheeking. So how to miss this checking when I click "Cancel" button.


<asp:TextBox id="Code" runat="server" MaxLength="13"></asp:TextBox>
<input type="submit" value="Submit" name="submit" runat="server" onserverclick="OnSubmit" />
<input type="submit" value="Cancel" name="cancel" runat="server" onserverclick="Cancel_Click" />
<asp:RequiredFieldValidator id="RequiredFieldValidator" runat="server" ErrorMessage="No Code" ControlToValidate="Code" ForeColor="White"></asp:RequiredFieldValidator>

Thanks !
0
rhinoceros
Asked:
rhinoceros
1 Solution
 
mmarinovCommented:
Hi rhinoceros,

use this:
<input type="submit" value="Cancel" name="cancel" runat="server" onserverclick="Cancel_Click" CausesValidation ="false" />

Regards!
B..M
0
 
RejojohnyCommented:
it is the "causesvalidation" property that decided whether the page validation has to executed or not  .. by default it is true for all server controls .. so by setting it to false for a particular .. the validation scripts will not be run on the client side for just that control ..

pls note, i just elborated on what mmarinov had already mentioned in the above example ...
0
 
rhinocerosAuthor Commented:
Rejojohny

Thanks for your comment indeed

But I need to miss the validation when I click "Cancel" button. (to do something such as "Redirect"). I can do it as I think, so mmarinov's answer is good me.


Thanks again!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now