Validators not preventing postbacks

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

    #1

    Validators not preventing postbacks

    Hi,

    I have 2 different web pages, both using RequiredFieldVa lidator's, on
    the one page Postbacks are prevented when required fields are blank,
    on the other page the validators display the error messages after the
    postback has returned, but neither the client side, nor the server
    side processing is suppressed (my incomplete data is written to my
    table)

    Any idea what could be wrong?

  • =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=

    #2
    RE: Validators not preventing postbacks

    Hi there,

    First if you want to prevent the post from the client browser set
    EnableClientScr ipt to true. Second, we can't rely on client script validation
    as it's very easy to prepare a page that simply skips it. Anyway, the problem
    is you don't check IsValid property before executing database insertion code.
    Valdators do not prevent page execution automatically (apart from client
    side), therefore before you perfom any action, you need to check if page
    passed validation (in other words, if all the validators are valid):

    protected void MyInsertButtonC lick(object sender, EventArgs e)
    {
    if (this.IsValid)
    {
    // insert data to database
    }
    }

    Hope this helps
    --
    Milosz


    "AD" wrote:
    Hi,
    >
    I have 2 different web pages, both using RequiredFieldVa lidator's, on
    the one page Postbacks are prevented when required fields are blank,
    on the other page the validators display the error messages after the
    postback has returned, but neither the client side, nor the server
    side processing is suppressed (my incomplete data is written to my
    table)
    >
    Any idea what could be wrong?
    >
    >

    Comment

    • AD

      #3
      Re: Validators not preventing postbacks

      Hi Milosz,

      Thanks for the response.

      Both EnableClientScr ipt and Enabled is true on the Validator control,
      on both pages, on the one page the postback is prevented, on the other
      it is not, anything else I can check?

      Comment

      • Toty Santana

        #4
        Re: Validators not preventing postbacks



        check that the db update control has the "CausesValidati on" property set to True.

        Check the validation group, the db update button(or what ever control you are using) and validation should have the same validation group or they both should have no validation if required.

        if non of the bove worked use Page.Validate() in the click event for the db update button, but u don't need to do that if "CausesValidati on" = True.
        "AD" <adriaandavel@y ahoo.co.ukwrote in message news:1176887946 .638462.133160@ n59g2000hsh.goo glegroups.com.. .
        Hi Milosz,

        Thanks for the response.

        Both EnableClientScr ipt and Enabled is true on the Validator control,
        on both pages, on the one page the postback is prevented, on the other
        it is not, anything else I can check?

        Comment

        • =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=

          #5
          Re: Validators not preventing postbacks

          Make sure you check the button has got CausesValidatio n set to true, and the
          code tests for IsValid in button's event handler:

          if (Page.IsValid)
          {
          // collect values and insert into a databse
          }

          hope this helps
          --
          Milosz


          "AD" wrote:
          Hi Milosz,
          >
          Thanks for the response.
          >
          Both EnableClientScr ipt and Enabled is true on the Validator control,
          on both pages, on the one page the postback is prevented, on the other
          it is not, anything else I can check?
          >
          >

          Comment

          Working...