Master Page按钮触发验证控件

时间:2022-05-31 14:58:26

There are several linkbutton controls in my masterpage, I bind click event to redirect to other pages, it works. But if my content page has Validator, it doesn't works. When I click the linkbutton, the validator will stop the event, what should I do to resolve it? Thanks.

我的母版页中有几个linkbutton控件,我绑定click事件以重定向到其他页面,它的工作原理。但是如果我的内容页面有Validator,它就不起作用。当我点击链接按钮时,验证器将停止该事件,我该怎么做才能解决它?谢谢。

Page.aspx

Page.aspx

<asp:LinkButton ID="lnkbtnHomePage" runat="server" Font-Underline="true" ForeColor="White" OnClick="lnkbtnHomePage_Click">HomePage</asp:LinkButton>

Page.aspx.cs

Page.aspx.cs

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

2 个解决方案

#1


1  

There are two options which you can use for this.

您可以使用两种方法。

The first is to add the attribute CausesValidation="false" to the buttons which you do not want to trigger any validation on the page.

第一种是将属性CausesValidation =“false”添加到您不希望在页面上触发任何验证的按钮。

The second option is to add the ValidationGroup="[groupname]" attribute to the controls and buttons which you want to trigger the validation.

第二个选项是将ValidationGroup =“[groupname]”属性添加到要触发验证的控件和按钮。

The first option is good if you have a one or two buttons on the page which shouldn't trigger the validation, however the second options gives you a safeguard against you adding a new controls which could interfere with your validation.

如果页面上有一个或两个不应触发验证的按钮,则第一个选项很好,但是第二个选项可以防止您添加可能会影响验证的新控件。

The second option is also very handy when you have different sections of a page which have their own validation groups and shouldn't effect others. For example if you have some standard controls on your master page which are shown throughout your site, but then have individual pages with their own forms. You can easily control their behaviour.

如果页面的不同部分具有自己的验证组且不应影响其他部分,则第二个选项也非常方便。例如,如果您的母版页上有一些标准控件,这些控件会显示在整个站点中,但随后会有各自的页面显示自己的表单。您可以轻松控制他们的行为。

However, as Yassine Houssni has mentioned, you would be better off just using standard <a> tags or even <asp:HyperLink> controls for simple behaviour as changing pages. If your link suddenly changes, then you will need to recompile the project rather than being able to update the link within the .aspx/master page.

但是,正如Yassine Houssni所提到的,你最好只使用标准的标签甚至是 控件来改变页面的简单行为。如果链接突然改变,那么您将需要重新编译项目,而不是能够更新.aspx / master页面中的链接。 :hyperlink>

#2


0  

hope this help http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.causesvalidation.aspx

希望这个帮助http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.causesvalidation.aspx

u can pass validation for link button http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton.causesvalidation.aspx

你可以通过链接按钮验证http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton.causesvalidation.aspx

#1


1  

There are two options which you can use for this.

您可以使用两种方法。

The first is to add the attribute CausesValidation="false" to the buttons which you do not want to trigger any validation on the page.

第一种是将属性CausesValidation =“false”添加到您不希望在页面上触发任何验证的按钮。

The second option is to add the ValidationGroup="[groupname]" attribute to the controls and buttons which you want to trigger the validation.

第二个选项是将ValidationGroup =“[groupname]”属性添加到要触发验证的控件和按钮。

The first option is good if you have a one or two buttons on the page which shouldn't trigger the validation, however the second options gives you a safeguard against you adding a new controls which could interfere with your validation.

如果页面上有一个或两个不应触发验证的按钮,则第一个选项很好,但是第二个选项可以防止您添加可能会影响验证的新控件。

The second option is also very handy when you have different sections of a page which have their own validation groups and shouldn't effect others. For example if you have some standard controls on your master page which are shown throughout your site, but then have individual pages with their own forms. You can easily control their behaviour.

如果页面的不同部分具有自己的验证组且不应影响其他部分,则第二个选项也非常方便。例如,如果您的母版页上有一些标准控件,这些控件会显示在整个站点中,但随后会有各自的页面显示自己的表单。您可以轻松控制他们的行为。

However, as Yassine Houssni has mentioned, you would be better off just using standard <a> tags or even <asp:HyperLink> controls for simple behaviour as changing pages. If your link suddenly changes, then you will need to recompile the project rather than being able to update the link within the .aspx/master page.

但是,正如Yassine Houssni所提到的,你最好只使用标准的标签甚至是 控件来改变页面的简单行为。如果链接突然改变,那么您将需要重新编译项目,而不是能够更新.aspx / master页面中的链接。 :hyperlink>

#2


0  

hope this help http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.causesvalidation.aspx

希望这个帮助http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.causesvalidation.aspx

u can pass validation for link button http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton.causesvalidation.aspx

你可以通过链接按钮验证http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton.causesvalidation.aspx