如何在ASP.NET网页中保留两个不同功能的按钮?

时间:2017-08-15 18:06:24

标签: c# asp.net

我想建立一个网站。以下截图是我的登录/注册链接页面。当我点击“登录”按钮而不提供任何数据时,它会显示一个警告。没关系。但问题是,当我按下注册按钮进入注册/注册页面时,那时“文本框”也显示了我的验证。这就是为什么我无法进入注册/注册页面。

<table id="Table2" runat="server" align="center" style="margin-top:15px; width:72%; height:170px">
                              <tr style="text-align:center; width:80%; height:8px;">
                                  <td style="font-size:medium; font-family:Courier New; font-weight:bold ;color:#000000; text-align:left ; width:20%; height:8px;">Mobile No</td>
                                  <td style=" width:40%;height:8px"><input type="number" id="mobnum"  runat="server" style="width:70%; height:23px" required="required" /></td>
                                 

                              </tr>
                              <tr style="text-align:center; width:80%; height:8px">
                                  <td style="font-size:medium; font-family:Courier New; font-weight:bold ;color:#000000; text-align:left ; width:30%; height:8px">Password</td>
                                  <td style="width:50%; height:8px"><asp:TextBox id="TextBox8" runat="server" style="width:70%; height:23px;" TextMode="Password" re ></asp:TextBox></td>
                              </tr>
                              <tr style="text-align:center; width:80%; height:29px">
                                  <td style="width:30%; height:29px"></td>
                                  <td style="width:50%; height:29px"><asp:Button ID="Button2" runat="server" ValidationGroup="IsValid"  height="30px" width="100px" BackColor="#006400" BorderColor="White" BorderStyle="None" ForeColor="White" Text="Login" Font-Bold="true" /></td>
                              </tr>
                          </table>
                          
                          <table id="Table4" runat="server" align="center" style="margin-top:15px; width: 72%; height:170px">
                              <tr style="text-align:center; width:100%; height:8px;">
                                  <td style="width:100%; height:10px; text-align:center"><asp:Button ID="Button1" runat="server" PostBackUrl="~/Signup.aspx" CausesValidation="false" height="30px" width="100px" BackColor="#006400" BorderColor="White" BorderStyle="None" ForeColor="White" Text="Register" Font-Bold="true" OnClick="Button1_Click" /></td>
                              </tr>
                              <tr style="text-align:center; width:80%; height:22px;">
                                  <td style="width:100%; height:22px"></td>
                              </tr>
                          </table>

3 个答案:

答案 0 :(得分:0)

您需要根据不同的操作分组每页(或)的验证。实质上你应该寻找Specifying Validation Groups

答案 1 :(得分:0)

只需将属性CausesValidation =“false”添加到“注册”按钮。

喜欢这个

<asp:Button runat="server" OnClick="OnClick" CausesValidation="false"/>

这将跳过您网页上的任何验证,并允许您转到注册页面。

答案 2 :(得分:0)

有两种方法可以处理这种情况; 1.在regester / signup按钮中,将CauseValidation设置为false。

  1. 设置Login按钮的ValidationGroup属性,并为所有验证器提供相同的ValidationGroup名称。