asp.net中的验证错误 [英] validation errors in asp.net

查看:102
本文介绍了asp.net中的验证错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


when i click my cancel button the page has to redirect to branch.aspx,but it is showing validation errors.

推荐答案

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


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


这篇关于asp.net中的验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆