problem with customvalidator inside updatepanel

Discussion in 'ASP .Net' started by Anton, Sep 5, 2009.

  1. Anton

    Anton Guest

    hi

    asp.net 3.5

    On my form I got a textbox and a linkbutton. I've associated a
    requiredfieldvalidator and a customvalidator to the textbox.

    The problem is that when I click on the linkbutton the ServerValidate_test
    code is executed (that is normal), BUT then it executes the rest of the code
    behind the linkbutton. So it looks like the linkbutton doesn't care of the
    result from the customvalidator.....

    customvalidator markup:
    <asp:CustomValidator ID="valCustom" runat="server"
    ValidationGroup="vg" ControlToValidate="txt1"
    EnableClientScript="false"
    OnServerValidate="ServerValidate_test"
    ErrorMessage="Error message">*
    </asp:CustomValidator>

    ServerValidate_test code:
    protected void ServerValidate_test(object sender, ServerValidateEventArgs e)
    {
    e.IsValid = false;
    }

    Linkbutton:
    <asp:LinkButton ID="lb" runat="server" CausesValidation="true"
    ValidationGroup="vg" OnClick="lb_Click">Save</asp:LinkButton>

    I haven't specified <Triggers> in the updatepanel...

    any suggestions?
     
    Anton, Sep 5, 2009
    #1
    1. Advertising

  2. Anton

    miher Guest

    "Anton" <no_email> az alábbiakat írta a következõ üzenetben
    news:...
    > hi
    >
    > asp.net 3.5
    >
    > On my form I got a textbox and a linkbutton. I've associated a
    > requiredfieldvalidator and a customvalidator to the textbox.
    >
    > The problem is that when I click on the linkbutton the ServerValidate_test
    > code is executed (that is normal), BUT then it executes the rest of the
    > code behind the linkbutton. So it looks like the linkbutton doesn't care
    > of the result from the customvalidator.....
    >
    > customvalidator markup:
    > <asp:CustomValidator ID="valCustom" runat="server"
    > ValidationGroup="vg" ControlToValidate="txt1"
    > EnableClientScript="false"
    > OnServerValidate="ServerValidate_test"
    > ErrorMessage="Error message">*
    > </asp:CustomValidator>
    >
    > ServerValidate_test code:
    > protected void ServerValidate_test(object sender, ServerValidateEventArgs
    > e)
    > {
    > e.IsValid = false;
    > }
    >
    > Linkbutton:
    > <asp:LinkButton ID="lb" runat="server" CausesValidation="true"
    > ValidationGroup="vg" OnClick="lb_Click">Save</asp:LinkButton>
    >
    > I haven't specified <Triggers> in the updatepanel...
    >
    > any suggestions?



    Hi,

    As far i know this is working as intended, since the validation controls
    won't stop event processing they just check the validity of the control they
    assigned to. This can be a bit confusing since if client sripts are enabled
    the validation javascript will not post the form if validation fails, but
    when the validation run on server side (and it always should run on server
    side too since client javascript can be hacked), it wont stop event
    processing just sets Page.IsValid. You should check for that in Your button
    event handler.
    Please check http://msdn.microsoft.com/en-us/library/a0z2h4sw(VS.80).aspx
    for example.

    Hope You find this useful.
    -Zsolt
     
    miher, Sep 6, 2009
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    5,164
  2. Replies:
    3
    Views:
    481
    Rob Meade
    Aug 8, 2007
  3. Leon Mayne
    Replies:
    5
    Views:
    4,774
    Leon Mayne
    May 27, 2008
  4. Nathan Sokalski
    Replies:
    1
    Views:
    589
    miher
    Jun 15, 2009
  5. musosdev
    Replies:
    1
    Views:
    595
    musosdev
    Sep 28, 2009
Loading...

Share This Page