john true
john true

Reputation: 273

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;

enter image description here

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 ?

Upvotes: 0

Views: 170

Answers (1)

hardkoded
hardkoded

Reputation: 21637

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" />

Upvotes: 1

Related Questions