Validation only when the user hits button

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pawel Pabich

    #1

    Validation only when the user hits button

    Hi,

    I have very simple code:

    <asp:TextBox ID="TextBox1" runat="server"/>
    <asp:RequiredFi eldValidator ID="RequiredFie ldValidator1" runat="server"

    ControlToValida te="TextBox1"
    ValidationGroup ="1"> <asp:Button ID="Button1" runat="server"
    Text="Button 1" ValidationGroup ="1"
    CausesValidatio n="true" />

    I would like RequiredFieldVa lidator1 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
    RequiredFieldVa lidator1 from firing too early?

    thanks in advance for any info

    Pawel Pabich

  • Karl Seguin [MVP]

    #2
    Re: Validation only when the user hits button

    You can try setting the CausesValidatio n 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

    --
    Programming blog exploring Zig, Elixir, Go, Testing, Design and Performance




    "Pawel Pabich" <pawel.pabich@g mail.com> wrote in message
    news:1149074277 .640065.203640@ h76g2000cwa.goo glegroups.com.. .[color=blue]
    > Hi,
    >
    > I have very simple code:
    >
    > <asp:TextBox ID="TextBox1" runat="server"/>
    > <asp:RequiredFi eldValidator ID="RequiredFie ldValidator1" runat="server"
    >
    > ControlToValida te="TextBox1"
    > ValidationGroup ="1"> <asp:Button ID="Button1" runat="server"
    > Text="Button 1" ValidationGroup ="1"
    > CausesValidatio n="true" />
    >
    > I would like RequiredFieldVa lidator1 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
    > RequiredFieldVa lidator1 from firing too early?
    >
    > thanks in advance for any info
    >
    > Pawel Pabich
    >[/color]


    Comment

    • Pawel Pabich

      #3
      Re: Validation only when the user hits button

      Hi Karl,

      thanks for your answer but it does not help. It makes sense to set
      CausesValidatio n 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

      Karl Seguin [MVP] wrote:[color=blue]
      > You can try setting the CausesValidatio n 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
      >
      > --
      > http://www.openmymind.net/
      >
      >
      >
      > "Pawel Pabich" <pawel.pabich@g mail.com> wrote in message
      > news:1149074277 .640065.203640@ h76g2000cwa.goo glegroups.com.. .[color=green]
      > > Hi,
      > >
      > > I have very simple code:
      > >
      > > <asp:TextBox ID="TextBox1" runat="server"/>
      > > <asp:RequiredFi eldValidator ID="RequiredFie ldValidator1" runat="server"
      > >
      > > ControlToValida te="TextBox1"
      > > ValidationGroup ="1"> <asp:Button ID="Button1" runat="server"
      > > Text="Button 1" ValidationGroup ="1"
      > > CausesValidatio n="true" />
      > >
      > > I would like RequiredFieldVa lidator1 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
      > > RequiredFieldVa lidator1 from firing too early?
      > >
      > > thanks in advance for any info
      > >
      > > Pawel Pabich
      > >[/color][/color]

      Comment

      Working...