0

我有一个网页,其中包含一个注册表单和一个登录表单,用户可以在其中注册或登录。

我的问题是当我尝试在登录文本框上注册验证时,停止请求进入服务器。此外,当我从该页面登录时,注册表单控件上的验证控件停止请求进入服务器。我应该尝试什么?

我曾尝试使用更新面板,但这不起作用。

这是我的代码:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <table width="400px" style="height:30px">
            <tr>
                <td class="style3" colspan="2">
                    <div class="register-bg">
                        <div class="padl20 padt5">
                            <span style="color:#2D432C">Registration Here</span>
                        </div>
                    </div>
                </td>
            </tr>
        </table>
        <table id="hpreg" style="height:380px; width: 358px;">
            <tr >
                <td style="width: 159px">
                    <b>Full Name</b>
                </td>
                <td style="width: 187px" class="wdth180">
                    <asp:TextBox ID="txt_nam" runat="server" Width="170px" CssClass="textfield"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                    ControlToValidate="txt_nam" ErrorMessage="Please enter Name" ForeColor="Red">*</asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td style="width: 159px">
                    <b> Father Name</b>
                </td>
                <td class="wdth180" style="width: 187px">
                    <asp:TextBox ID="txt_fnam" runat="server" Width="170px" 
                    CssClass="textfield"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                    ControlToValidate="txt_fnam" ErrorMessage="Please enter father name" 
                    ForeColor="Red">*</asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td style="width: 159px">
                    <b> Gender</b>
                </td>
                <td class="wdth180" style="width: 187px">
                    <asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatColumns="2" 
                    ToolTip="Enter Your Gender" Width="160px" CssClass="radio wdth130">
                    <asp:ListItem Value="M">Male</asp:ListItem>
                    <asp:ListItem Value="F">Female</asp:ListItem>
                </asp:RadioButtonList>
                </td>
            </tr>

......

在同一页面上登录 html 是这样的:

<asp:Content ID="Content2" runat="server" 
contentplaceholderid="ContentPlaceHolder2">
    <table width="240px" >
        <tr style="height:28px;">
            <td>
                <b><asp:TextBox runat="server"  ID="TextBox1" CssClass="textfield"/></b>
            </td>
            <td>
                <asp:TextBox runat="server" ID="TextBox2" TextMode="Password" CssClass="textfield"  />
            </td>
        </tr>
        <tr style="height:28px;">
            <td><asp:LinkButton ID="LinkButton1" runat="server">Forget Password</asp:LinkButton>
            </td>
            <td> <asp:Button ID="btn_login" CssClass="medimum-btn wdth45" runat="server" Text="Login" onclick="btn_login_Click" />
            </td>
        </tr>
        <tr style="height:28px;">
            <td></td>
            <td></td>
        </tr>
    </table>
    <div class="fleft">
    </div>
    <br />
    <div class="fleft padl5">
    </div>
    <div class="fleft padl5">
        <br />  
    </div>
</asp:Content>
4

2 回答 2

3

您需要ValidationGroup在验证器和摘要上使用该属性。

创建两组,一组用于登录,一组用于注册。

这是一些未经测试的代码,可以让您了解...

<asp:Panel runat="server" id="pnlLogon" DefaultButton="btnLogon">
  <asp:ValidationSummary runat="server" id="sumLogon"
    ValidationGroup="valLogonGroup" />
  Username: <asp:TextBox runat="server" id="txtUsername" />
  <asp:RequiredFieldValidator runat="server" ControlToValidate="txtUsername"
    ValidationGroup="valLogonGroup" ErrorMessage="Provide Username"/><br/>
  Password: <asp:TextBox runat="server" id="txtPassword" />
  <asp:RequiredFieldValidator runat="server" ControlToValidate="txtPassword"
    ValidationGroup="valLogonGroup" ErrorMessage="Provide Password"/><br/>
  <asp:Button runat="server" id="btnLogon" ValidationGroup="valLogonGroup"
    Text="Logon"/>
</asp:Panel>
<asp:Panel runat="server" id="pnlRegister" DefaultButton="btnRegister">
  <asp:ValidationSummary runat="server" id="sumRegister"
    ValidationGroup="valRegisterGroup" />
  Full Name: <asp:TextBox runat="server" id="txtName" />
  <asp:RequiredFieldValidator runat="server" ControlToValidate="txtName"
    ValidationGroup="valRegisterGroup" ErrorMessage="Provide Full Name"/><br/>
  Password: <asp:TextBox runat="server" id="txtPassword" />
  <asp:RequiredFieldValidator runat="server" ControlToValidate="txtPassword"
    ValidationGroup="valRegisterGroup" ErrorMessage="Provide Password"/><br/>
  <asp:Button runat="server" id="btnRegister" ValidationGroup="valRgisterGroup"
    Text="Register"/>
</asp:Panel>

我已将它们放入<asp:Panel>以利用DefaultButton. 这意味着,如果您在 中的文本框中按enterreturn键,则会单击<asp:Panel>正确<asp:Button>的...并且由于各个按钮链接到特定的特定按钮,因此ValidationGroup只会触发该组的验证器。

于 2013-09-20T12:34:18.233 回答
1

在这种情况下应使用验证组:

 <table width="240px">
     <tr style="height: 28px;">
         <td>
             <b><asp:TextBox runat="server" ID="TextBox1" CssClass="textfield"  
                             ValidationGroup="loginGrp"/></b>
         </td>
         <td>
             <asp:TextBox runat="server" ID="TextBox2" TextMode="Password" 
                          CssClass="textfield"  ValidationGroup="loginGrp" />
         </td>
     </tr>
    <tr style="height: 28px;">
         <td>
             <asp:LinkButton ID="LinkButton1" CauseValidation="false" 
                             runat="server">Forget Password</asp:LinkButton>
         </td>
         <td>
             <asp:Button ID="btn_login" CssClass="medimum-btn wdth45" runat="server" 
                         Text="Login" ValidationGroup="loginGrp"
                         OnClick="btn_login_Click" />
         </td>
     </tr>
于 2013-09-20T12:37:16.350 回答