如何绕过ASP.NET中的按钮验证?

时间:2021-06-11 03:18:10

I have an ASP.NET form that takes input from a user. There's a Submit button on the form and a button called Calc which does a calculation to populate a text field. The problem I'm having is that on the form I have a set of <ASP:REQUIREDFIELDVALIDATOR> validators and when the Calc button is pressed the form gets validated. I don't want the required fields to be validated when the Calc button is pressed, only the Submit button. Any way around this?

我有一个ASP。接收用户输入的NET表单。表单上有一个提交按钮和一个名为Calc的按钮,该按钮进行填充文本字段的计算。我遇到的问题是,在窗体上有一组 验证器,当按下Calc按钮时,窗体就会得到验证。当按下Calc按钮时,我不希望对必需的字段进行验证,只需要提交按钮。解决这个问题的办法吗?

6 个解决方案

#1


59  

Set the CausesValidation property to false.

将CausesValidation属性设置为false。

#2


18  

<asp:Button runat="Server" ... CausesValidation="False" />

Button.CausesValidation (If I remember correctly).

按钮。因果验证(如果我没记错的话)。

#3


4  

Try putting CausesValidation="false" as a button attribute.

尝试将CausesValidation=“false”作为按钮属性。

Some sample code:

一些示例代码:

http://weblogs.asp.net/scottgu/archive/2005/08/04/421647.aspx

http://weblogs.asp.net/scottgu/archive/2005/08/04/421647.aspx

#4


4  

ASPX Page:

ASPX页面:

<asp:Button ID="buttonNew" runat="server" Text="New" CausesValidation="False" />

OR

CodeBehind Page: (.cs)

后台代码页(cs):

buttonNew.CausesValidation = false;

Check here to know more about Validated and Validating events for the controls.

请在这里检查,以了解有关控件的验证和验证事件的更多信息。

#5


2  

Set the button.causesValidation to false.

设置按钮。causesValidation为假。

this link

这个链接

However, if all it is doing is calculating something based on user input then you shouldn't have it posting back at all. I would recommend using an HTML button and attach some javascript to it to do your work for you and then you won't have this problem.

但是,如果它所做的只是基于用户输入来计算某个东西,那么你就不应该把它放回原处。我建议使用一个HTML按钮并附加一些javascript来为您完成工作,这样您就不会有这个问题了。

#6


1  

While designing the button, you can set its property CausesValidation="false" to avoid validation on button click event. It does not allow to validation the server control and perform its click event only

在设计按钮时,您可以设置其属性CausesValidation=“false”,以避免在按钮单击事件上进行验证。它不允许验证服务器控件并只执行它的单击事件。

#1


59  

Set the CausesValidation property to false.

将CausesValidation属性设置为false。

#2


18  

<asp:Button runat="Server" ... CausesValidation="False" />

Button.CausesValidation (If I remember correctly).

按钮。因果验证(如果我没记错的话)。

#3


4  

Try putting CausesValidation="false" as a button attribute.

尝试将CausesValidation=“false”作为按钮属性。

Some sample code:

一些示例代码:

http://weblogs.asp.net/scottgu/archive/2005/08/04/421647.aspx

http://weblogs.asp.net/scottgu/archive/2005/08/04/421647.aspx

#4


4  

ASPX Page:

ASPX页面:

<asp:Button ID="buttonNew" runat="server" Text="New" CausesValidation="False" />

OR

CodeBehind Page: (.cs)

后台代码页(cs):

buttonNew.CausesValidation = false;

Check here to know more about Validated and Validating events for the controls.

请在这里检查,以了解有关控件的验证和验证事件的更多信息。

#5


2  

Set the button.causesValidation to false.

设置按钮。causesValidation为假。

this link

这个链接

However, if all it is doing is calculating something based on user input then you shouldn't have it posting back at all. I would recommend using an HTML button and attach some javascript to it to do your work for you and then you won't have this problem.

但是,如果它所做的只是基于用户输入来计算某个东西,那么你就不应该把它放回原处。我建议使用一个HTML按钮并附加一些javascript来为您完成工作,这样您就不会有这个问题了。

#6


1  

While designing the button, you can set its property CausesValidation="false" to avoid validation on button click event. It does not allow to validation the server control and perform its click event only

在设计按钮时,您可以设置其属性CausesValidation=“false”,以避免在按钮单击事件上进行验证。它不允许验证服务器控件并只执行它的单击事件。