开发者

Two ASP.net buttons on same page problem?

I have two asp buttons on a single page. In the following format textbox1 required field validator1 button1

textbox2 required filed validator2 button2

if I keep cause validation on both buttons true, then its not firing the server side click event, but I am able to validate these text bo开发者_开发技巧xes using required field validators.

If I keep this cause validation on both buttons false, its firing the server side click event, but I am not able to validate these textboxes using required filed validators

Can you please tell me the best solution

Thanks


CausesValidation should be true on both.

What you need to do is set ValidationGroup Button1Validation on the textbox1 validator and button1. Set a ValidationGroup of Button2Validation on the textbox2 validator and button2.

Validation groups separate validation rules into groups so that the groups don't overlap and interfere with each other.


The default behavior of the RequiredFieldValidator is that when you don't insert something into the textbox to which it's coupled, and client side validation is turned on (defaults to true), then it won't posback and as such the server side event never gets hit.

You can turn off the client side validation on the validator control by setting the property EnableClientScript to false:

<asp:RequiredFieldValidator ID="TextBoxRequiredValidator" 
    ControlToValidate="NumberTextBox"
    EnableClientScript="False"
    Display="Dynamic" 
    ErrorMessage="Please enter a value."
    Text="*"
    runat="server"/>

Taken from the MSDN documentation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜