Validation only when the user hits button

  • Thread starter Thread starter Pawel Pabich
  • Start date Start date
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
 
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
 
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
 
Back
Top