Miss the RequiredFieldValidator checking

Posted on 2004-11-05
Last Modified: 2008-03-06

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 !
Question by:rhinoceros
    LVL 28

    Accepted Solution

    Hi rhinoceros,

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

    LVL 26

    Expert Comment

    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 ...
    LVL 13

    Author Comment


    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!

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    This video discusses moving either the default database or any database to a new volume.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now