如何在不影响必填字段验证器的情况下使 "link_click" 工作?

How can i make the "link_click" work without affecting the required field validators?

为了详细说明我的问题,我有购物车网站。我还有用户名、地址、联系人等文本框。所有这些都有必填字段验证器。但是我在页面上也确实有 "view profile" 和 "log out" link 按钮。当我尝试点赞那些 link 时,它不允许我点赞,因为必填字段未填写。我可以用这个做什么技巧吗?感谢您的任何回答:)

这是我的代码。

<asp:TextBox ID="txtCustomerName" runat="server" Width="231px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
    ErrorMessage="Customer Name is Required." ForeColor="Red" ControlToValidate="txtCustomerName"
    ></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
    <td align="left">
        Phone No:
    </td>
</tr>
<tr>
    <td>
        <asp:TextBox ID="txtCustomerPhoneNo" runat="server" Width="231px" 
            MaxLength="11"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
            ErrorMessage="Phone Number is required." ForeColor="Red" ControlToValidate="txtCustomerPhoneNo"
            ></asp:RequiredFieldValidator>
    </td>
</tr>
<tr>
    <td align="left">
        EmailID:
    </td>
</tr>
<tr>
    <td>
        <asp:TextBox ID="txtCustomerEmailID" runat="server" Width="231px"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
            ErrorMessage=" Email Address is Required." ForeColor="Red" ControlToValidate="txtCustomerEmailID"
            ></asp:RequiredFieldValidator>
    </td>

这是我的 link 代码。

 protected void link_ViewProfile_Click(object sender, EventArgs e)
    {
        Response.Redirect("viewprofile.aspx");
    }

    protected void link_Logout_Click(object sender, EventArgs e)
    {
        Session.Clear();
        Response.Redirect("Home.aspx");
    }

这里是 link 我是如何设法解决它的。 https://msdn.microsoft.com/en-us/library/ms227424(v=vs.140).aspx。感谢@Tonny

对于您想要 运行 验证的那些 link 按钮,添加验证组属性。例如

<asp:button id="Button2" 
  text="Validate" 
  causesvalidation="true"
  validationgroup="LocationInfoGroup"
  runat="Server" />

同时在 RequiredFieldValidator 中添加 validationgroup 属性

<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
            ErrorMessage="Phone Number is required." ForeColor="Red" ControlToValidate="txtCustomerPhoneNo"
validationgroup="LocationInfoGroup"
            ></asp:RequiredFieldValidator>