Refresh questions

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

    #1

    Refresh questions

    Before someone flames me, I know this is the VB.NET groups, nonetheless, the
    asp.net guys seems to have almost disapeared from the aspnet groups so I
    thought I would ask this here.

    I have a problem with an aspx web form in that if I refresh, it simply
    resubmits the form and causes multiple submissions, in this case the form is
    one which adds records to the database and refreshing a previously submitted
    item repeats each time the refresh is clicked.

    Does anyone have a suggestion on how I can get around this ?

    Thanks

    --
    Best Regards

    The Inimitable Mr Newbie º¿º


  • cbrown@duclaw.com

    #2
    Re: Refresh questions

    Add this to your page_load event

    If Not Page.IsPostBack Then
    'The code currently in your Load event
    End If

    Comment

    • Mr Newbie

      #3
      Re: Refresh questions

      No that wont help because this form can postback several times, it is the
      false submission which I am after, in other words the code behind the
      submit button re-runs on refresh

      --
      Best Regards

      The Inimitable Mr Newbie º¿º
      <cbrown@duclaw. com> wrote in message
      news:1137698093 .021034.80690@z 14g2000cwz.goog legroups.com...[color=blue]
      > Add this to your page_load event
      >
      > If Not Page.IsPostBack Then
      > 'The code currently in your Load event
      > End If
      >[/color]


      Comment

      • cbrown@duclaw.com

        #4
        Re: Refresh questions

        Well, I guess it really depends on what the code does. You could store
        something in View or Session state that gets checked on each submit.
        Depends how you feel about Session objects. Cant help much more
        without seeing the code or knowing what the code does.

        Comment

        • _AnonCoward

          #5
          Re: Refresh questions


          "Mr Newbie" <here@now.com > wrote in message
          news:%23ZSECiSH GHA.344@TK2MSFT NGP11.phx.gbl.. .
          : Before someone flames me, I know this is the VB.NET groups, nonetheless,
          : the asp.net guys seems to have almost disapeared from the aspnet groups
          : so I thought I would ask this here.
          :
          : I have a problem with an aspx web form in that if I refresh, it simply
          : resubmits the form and causes multiple submissions, in this case the form
          : is one which adds records to the database and refreshing a previously
          : submitted item repeats each time the refresh is clicked.
          :
          : Does anyone have a suggestion on how I can get around this ?
          :
          : Thanks
          :
          : --
          : Best Regards
          :
          : The Inimitable Mr Newbie º¿º


          I had a problem like that once. What I ended up doing was creating a field
          in my database that stored a submission ID and checking it when the page is
          submitted. When the page was initially loaded (not the post back), a unique
          value (including date time stamp in this case) was generated and included as
          a hidden field in the form.


          When the form was submitted I'd check that value to see if it existed in the
          database. If it didn't, I allowed the submission to be inserted into the
          database and I returned a response method appropriate the specifics of this
          submission. Part of the insert action was to add this value into the record.


          If the page was resubmitted, the same value would exist in the database when
          the page was processed. In this case, I did not attempt to update the
          database a 2nd time with the same values. I didn't object to the user or
          anything but instead simply returned the same response that I would have if
          I accepted the values.


          There is at least one down side to this. If the user actually refreshes the
          page, a new ID value would be generated and if submitted, the values would
          be inserted twice because the system would think of this as a unique
          submission. To get around that, I actually created the ID value two pages
          back and passed it forward in hidden fields. Each page would POST to the
          next in a cascading fashion. If the page in question was accessed directly
          (or for any other reason the ID field wasn't present in the Request.Form
          object when the page initially loaded), I'd redirect the user to the home
          page and force them to start over. That way they couldn't jump into the
          middle of the process and bypass this check.


          This way, the user would have to back up two pages and refresh in order to
          generate a new ID value. What actually happens is that the users start over
          with a new process which was the intention all along (the refresh/resubmits
          were never deliberate, rather they were the result of users being impatient
          and not understanding what was happening).


          I was never fully happy with the process (it just seemed somehow awfully
          contrived to me), but it works. We eliminated duplicate submissions in our
          system and the users seem no worse for the wear. This doesn't seem to be
          exactly what you are talking about, but perhaps a variation of this approach
          may serve your purposes.


          Ralf
          --
          --
          ----------------------------------------------------------
          * ^~^ ^~^ *
          * _ {~ ~} {~ ~} _ *
          * /_``>*< >*<''_\ *
          * (\--_)++) (++(_--/) *
          ----------------------------------------------------------
          There are no advanced students in Aikido - there are only
          competent beginners. There are no advanced techniques -
          only the correct application of basic principles.



          Comment

          • Mr Newbie

            #6
            Re: Refresh questions

            Excellent reply Ralf. I think I need to think this throught after what you
            have suggested.

            Thanks

            --
            Best Regards

            The Inimitable Mr Newbie º¿º
            "_AnonCowar d" <abcdef@uvwxyz. com> wrote in message
            news:SiUzf.2466 2$Kp.23139@sout heast.rr.com...[color=blue]
            >
            > "Mr Newbie" <here@now.com > wrote in message
            > news:%23ZSECiSH GHA.344@TK2MSFT NGP11.phx.gbl.. .
            > : Before someone flames me, I know this is the VB.NET groups, nonetheless,
            > : the asp.net guys seems to have almost disapeared from the aspnet groups
            > : so I thought I would ask this here.
            > :
            > : I have a problem with an aspx web form in that if I refresh, it simply
            > : resubmits the form and causes multiple submissions, in this case the
            > form
            > : is one which adds records to the database and refreshing a previously
            > : submitted item repeats each time the refresh is clicked.
            > :
            > : Does anyone have a suggestion on how I can get around this ?
            > :
            > : Thanks
            > :
            > : --
            > : Best Regards
            > :
            > : The Inimitable Mr Newbie º¿º
            >
            >
            > I had a problem like that once. What I ended up doing was creating a field
            > in my database that stored a submission ID and checking it when the page
            > is
            > submitted. When the page was initially loaded (not the post back), a
            > unique
            > value (including date time stamp in this case) was generated and included
            > as
            > a hidden field in the form.
            >
            >
            > When the form was submitted I'd check that value to see if it existed in
            > the
            > database. If it didn't, I allowed the submission to be inserted into the
            > database and I returned a response method appropriate the specifics of
            > this
            > submission. Part of the insert action was to add this value into the
            > record.
            >
            >
            > If the page was resubmitted, the same value would exist in the database
            > when
            > the page was processed. In this case, I did not attempt to update the
            > database a 2nd time with the same values. I didn't object to the user or
            > anything but instead simply returned the same response that I would have
            > if
            > I accepted the values.
            >
            >
            > There is at least one down side to this. If the user actually refreshes
            > the
            > page, a new ID value would be generated and if submitted, the values would
            > be inserted twice because the system would think of this as a unique
            > submission. To get around that, I actually created the ID value two pages
            > back and passed it forward in hidden fields. Each page would POST to the
            > next in a cascading fashion. If the page in question was accessed directly
            > (or for any other reason the ID field wasn't present in the Request.Form
            > object when the page initially loaded), I'd redirect the user to the home
            > page and force them to start over. That way they couldn't jump into the
            > middle of the process and bypass this check.
            >
            >
            > This way, the user would have to back up two pages and refresh in order to
            > generate a new ID value. What actually happens is that the users start
            > over
            > with a new process which was the intention all along (the
            > refresh/resubmits
            > were never deliberate, rather they were the result of users being
            > impatient
            > and not understanding what was happening).
            >
            >
            > I was never fully happy with the process (it just seemed somehow awfully
            > contrived to me), but it works. We eliminated duplicate submissions in our
            > system and the users seem no worse for the wear. This doesn't seem to be
            > exactly what you are talking about, but perhaps a variation of this
            > approach
            > may serve your purposes.
            >
            >
            > Ralf
            > --
            > --
            > ----------------------------------------------------------
            > * ^~^ ^~^ *
            > * _ {~ ~} {~ ~} _ *
            > * /_``>*< >*<''_\ *
            > * (\--_)++) (++(_--/) *
            > ----------------------------------------------------------
            > There are no advanced students in Aikido - there are only
            > competent beginners. There are no advanced techniques -
            > only the correct application of basic principles.
            >
            >
            >[/color]


            Comment

            • Mr Newbie

              #7
              Re: Refresh questions

              here's an article dedicated for the subject

              Preventing Duplicate Record Insertion on Page Refresh



              --
              Best Regards

              The Inimitable Mr Newbie º¿º
              "_AnonCowar d" <abcdef@uvwxyz. com> wrote in message
              news:SiUzf.2466 2$Kp.23139@sout heast.rr.com...[color=blue]
              >
              > "Mr Newbie" <here@now.com > wrote in message
              > news:%23ZSECiSH GHA.344@TK2MSFT NGP11.phx.gbl.. .
              > : Before someone flames me, I know this is the VB.NET groups, nonetheless,
              > : the asp.net guys seems to have almost disapeared from the aspnet groups
              > : so I thought I would ask this here.
              > :
              > : I have a problem with an aspx web form in that if I refresh, it simply
              > : resubmits the form and causes multiple submissions, in this case the
              > form
              > : is one which adds records to the database and refreshing a previously
              > : submitted item repeats each time the refresh is clicked.
              > :
              > : Does anyone have a suggestion on how I can get around this ?
              > :
              > : Thanks
              > :
              > : --
              > : Best Regards
              > :
              > : The Inimitable Mr Newbie º¿º
              >
              >
              > I had a problem like that once. What I ended up doing was creating a field
              > in my database that stored a submission ID and checking it when the page
              > is
              > submitted. When the page was initially loaded (not the post back), a
              > unique
              > value (including date time stamp in this case) was generated and included
              > as
              > a hidden field in the form.
              >
              >
              > When the form was submitted I'd check that value to see if it existed in
              > the
              > database. If it didn't, I allowed the submission to be inserted into the
              > database and I returned a response method appropriate the specifics of
              > this
              > submission. Part of the insert action was to add this value into the
              > record.
              >
              >
              > If the page was resubmitted, the same value would exist in the database
              > when
              > the page was processed. In this case, I did not attempt to update the
              > database a 2nd time with the same values. I didn't object to the user or
              > anything but instead simply returned the same response that I would have
              > if
              > I accepted the values.
              >
              >
              > There is at least one down side to this. If the user actually refreshes
              > the
              > page, a new ID value would be generated and if submitted, the values would
              > be inserted twice because the system would think of this as a unique
              > submission. To get around that, I actually created the ID value two pages
              > back and passed it forward in hidden fields. Each page would POST to the
              > next in a cascading fashion. If the page in question was accessed directly
              > (or for any other reason the ID field wasn't present in the Request.Form
              > object when the page initially loaded), I'd redirect the user to the home
              > page and force them to start over. That way they couldn't jump into the
              > middle of the process and bypass this check.
              >
              >
              > This way, the user would have to back up two pages and refresh in order to
              > generate a new ID value. What actually happens is that the users start
              > over
              > with a new process which was the intention all along (the
              > refresh/resubmits
              > were never deliberate, rather they were the result of users being
              > impatient
              > and not understanding what was happening).
              >
              >
              > I was never fully happy with the process (it just seemed somehow awfully
              > contrived to me), but it works. We eliminated duplicate submissions in our
              > system and the users seem no worse for the wear. This doesn't seem to be
              > exactly what you are talking about, but perhaps a variation of this
              > approach
              > may serve your purposes.
              >
              >
              > Ralf
              > --
              > --
              > ----------------------------------------------------------
              > * ^~^ ^~^ *
              > * _ {~ ~} {~ ~} _ *
              > * /_``>*< >*<''_\ *
              > * (\--_)++) (++(_--/) *
              > ----------------------------------------------------------
              > There are no advanced students in Aikido - there are only
              > competent beginners. There are no advanced techniques -
              > only the correct application of basic principles.
              >
              >
              >[/color]


              Comment

              • Cor Ligthert [MVP]

                #8
                Re: Refresh questions

                Mr. Newbie,

                From the previous messages I get the idea that you are using an autokey. Try
                to avoid that. The nicest recordidentifie r in a database is the GUID



                I hope this helps,

                Cor


                Comment

                • Dennis

                  #9
                  Re: Refresh questions

                  Question; Why is the submit button click event fired if a page is refreshed?
                  --
                  Dennis in Houston


                  "Cor Ligthert [MVP]" wrote:
                  [color=blue]
                  > Mr. Newbie,
                  >
                  > From the previous messages I get the idea that you are using an autokey. Try
                  > to avoid that. The nicest recordidentifie r in a database is the GUID
                  >
                  > http://www.vb-tips.com/default.aspx?...3-fee3733fcd6f
                  >
                  > I hope this helps,
                  >
                  > Cor
                  >
                  >
                  >[/color]

                  Comment

                  • Mr Newbie

                    #10
                    Re: Refresh questions

                    Because the client must repost the header which has is a POST. I think
                    explorer seems to go one step further and emulates the last post completely
                    even if you clear the headers on pre-render event.

                    --
                    Best Regards

                    The Inimitable Mr Newbie º¿º
                    "Dennis" <Dennis@discuss ions.microsoft. com> wrote in message
                    news:60CBE176-9E6E-4E70-AA13-85A51A95D437@mi crosoft.com...[color=blue]
                    > Question; Why is the submit button click event fired if a page is
                    > refreshed?
                    > --
                    > Dennis in Houston
                    >
                    >
                    > "Cor Ligthert [MVP]" wrote:
                    >[color=green]
                    >> Mr. Newbie,
                    >>
                    >> From the previous messages I get the idea that you are using an autokey.
                    >> Try
                    >> to avoid that. The nicest recordidentifie r in a database is the GUID
                    >>
                    >> http://www.vb-tips.com/default.aspx?...3-fee3733fcd6f
                    >>
                    >> I hope this helps,
                    >>
                    >> Cor
                    >>
                    >>
                    >>[/color][/color]


                    Comment

                    Working...