Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: validation
<table align="center" cellpadding="4" cellspacing="4">
                    <tr>
                        <td align="right">
                            Code
                        </td>
                        <td align="left">
                            <asp:TextBox ID="TxtBrCode" runat="server"
                                ontextchanged="TxtBrCode_TextChanged" AutoPostBack="true"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Required"
                                Text="*" ControlToValidate="TxtBrCode"/>
                        </td>
                        <td align="right">
                            Name
                        </td>
                        <td align="left">
                            <asp:TextBox ID="TxtBrName" runat="server"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Required"
                                Text="*" ControlToValidate="TxtBrName"/>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            Region
                        </td>
                        <td align="left">
                            <asp:DropDownList ID="DdlRegion" runat="server">
                            </asp:DropDownList>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Required"
                                Text="*" ControlToValidate="DdlRegion"/>
                        </td>
                        <td align="right">
                            Phone
                        </td>
                        <td align="left">
                            <asp:TextBox ID="TxtPhone" runat="server"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Required"
                                Text="*" ControlToValidate="TxtPhone"/>
                            <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ErrorMessage="Invalid Phone Number"
                                Text="*" ControlToValidate="TxtPhone" ValidationExpression="\d{10}"/>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            Mobile
                        </td>
                        <td align="left">
                            <asp:TextBox ID="TxtMobile" runat="server"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ErrorMessage="Required"
                                Text="*" ControlToValidate="TxtMobile"/>
                            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Invalid Mobile Number"
                                Text="*" ControlToValidate="TxtMobile" ValidationExpression="\d{10}"/>
                        </td>
                        <td align="right">
                            Email
                        </td>
                        <td align="left">
                            <asp:TextBox ID="TxtEmail" runat="server"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ErrorMessage="Required"
                                Text="*" ControlToValidate="TxtEmail"/>
                            <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ErrorMessage="Invalid Email ID" Text="*"
                             ControlToValidate="TxtEmail" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"/>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            ContactPerson
                        </td>
                        <td align="left">
                            <asp:TextBox ID="TxtContactPerson" runat="server"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ErrorMessage="Required"
                                Text="*" ControlToValidate="TxtContactPerson"/>
                        </td>
                        <td align="right">
                            Address
                        </td>
                        <td align="left">
                            <asp:TextBox ID="TxtAddress" runat="server"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ErrorMessage="Required"
                                Text="*" ControlToValidate="TxtAddress"/>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="4" align="center">
                            <asp:Button ID="BtnSave" runat="server" Text="Save" OnClick="BtnSave_Click" />
                            <asp:Button ID="BtnCancel" runat="server" Text="Cancel" OnClick="BtnCancel_Click" />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="4" align="center">
                            <asp:ValidationSummary ID="VS" runat="server" CssClass="ValidationSummaryclass" ShowSummary="true" EnableClientScript="true"/>
                        </td>
                    </tr>
                </table>
protected void BtnCancel_Click(object sender, EventArgs e)
        {
           Response.Redirect("Branches.aspx");
        }
when i click my cancel button the page has to redirect to branch.aspx,but it is showing validation errors.
Posted 27-Jan-13 3:54am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi Ranga,
Change validation group for cancel button(I changed to 0) this will generate validation error(if required fields are blank) only when you click save button in your webpage.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hello My Dear Friend,
 
Go to your CANCEL Button properties and check Causes Validation properties
 
if it is true make it false
 
or
 
if it is false make it true.
 

 
This will work 100% am sure.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 150
2 Richard MacCutchan 135
3 PIEBALDconsult 110
4 Sergey Alexandrovich Kryukov 104
0 OriginalGriff 6,055
1 DamithSL 4,621
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,500
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 27 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100