Validation only when the user hits button

P

Pawel Pabich

Hi,

I have very simple code:

<asp:TextBox ID="TextBox1" runat="server"/>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"

ControlToValidate="TextBox1"
ValidationGroup="1"> <asp:Button ID="Button1" runat="server"
Text="Button 1" ValidationGroup="1"
CausesValidation="true" />

I would like RequiredFieldValidator1 to fire only when I hit Button1
button. But it also fires when
text box TextBox1 looses focus. For example when I finish typing and
hit TAB key. Is there any way in order to prevent
RequiredFieldValidator1 from firing too early?

thanks in advance for any info

Pawel Pabich
 
K

Karl Seguin [MVP]

You can try setting the CausesValidation property of the textbox to false.

ASP.NET 2.0 has far more granular control over validation. You can say "I
want all these validators to be fired by this button only, and this 2nd
group to be fired by this other button here"...

Karl
 
P

Pawel Pabich

Hi Karl,

thanks for your answer but it does not help. It makes sense to set
CausesValidation to fale when the text box casues post back and my
text box doesn't. I thought that if a validator is member of any
validation
group then it needs to wait for button or any other control that causes
validation
but it seems I'm wrong.

Pawel Pabich
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,226
Latest member
KristanTal

Latest Threads

Top