简体   繁体   中英

form validates whole page in ASP.NET

I want to validate only part of the page in the same form.

However it validates whole pages textboxes like below. Here is the details;

在此处输入图片说明

Code behind is;

<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
            .
            .
            .
            </ContentTemplate>
             <Triggers>
                 <asp:AsyncPostBackTrigger ControlID="btnLogin" EventName="Click" />
             </Triggers>
        </asp:UpdatePanel>

// the section that i want to validate only below textbox using reset button however above one is validating too

        <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
              <asp:TextBox ID="tbMailForgot" minlength="1" required="" runat="server"  TextMode="Email" ValidateRequestMode="Enabled"  ></asp:TextBox>
              <asp:Button ID="btnReset"  OnClientClick="return funcmail();" runat="server" Text="Reset"  OnClick="btnReset_Click" />
            </ContentTemplate>
             <Triggers>
                 <asp:AsyncPostBackTrigger ControlID="btnReset" EventName="Click" />
             </Triggers>
        </asp:UpdatePanel>
</form>

How can i do it partly ?

You can use Validation groups . You have to set each validator to a validation group and then set the same validation group to the submit button. For instance:

<asp:TextBox ID="tbMailForgot" minlength="1" required="" runat="server"  TextMode="Email" ValidateRequestMode="Enabled"></asp:TextBox>
<asp:requiredfieldvalidator id="RequiredFieldValidator2"
      controltovalidate="tbMailForgot"
      validationgroup="Forgot"
      errormessage="Email required"
      runat="Server">
    </asp:requiredfieldvalidator>
<asp:Button ID="btnReset" OnClientClick="return funcmail();" runat="server" Text="Reset" OnClick="btnReset_Click" ValidationGroup="Forgot" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM