【问题标题】:How to keep two buttons for two different functions in an ASP.NET web page?如何在 ASP.NET 网页中为两个不同的功能保留两个按钮?
【发布时间】:2017-08-15 18:06:24
【问题描述】:

我想做一个网站。以下屏幕截图是我的登录/注册链接页面。当我在不提供任何数据的情况下单击登录按钮时,它会向我显示警报。没关系。但问题是,当我按下注册按钮进入注册/注册页面时,当时“文本框”也在向我显示此验证。这就是我无法进入注册/注册页面的原因。

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

【问题讨论】:

标签: c# asp.net


【解决方案1】:

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

【讨论】:

  • 听起来他在登录页面上只有一个验证组,并且他在点击注册时试图重定向到注册页面。
【解决方案2】:

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

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

【讨论】:

    【解决方案3】:

    只需将属性 CausesValidation="false" 添加到您的注册按钮即可。

    这样

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

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

    【讨论】:

      猜你喜欢
      • 2011-04-18
      • 1970-01-01
      • 2023-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多