ASP.NET Refresh Problem

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

    #1

    ASP.NET Refresh Problem

    hello, i have a problem in refreshing a page. the problem happens when i
    click a button that does a certain action in a web page, such as inserting a
    record into the database, if now i refresh the page (press f5), the action
    repeats itself and another identical record is inserted too.
    i discovered that the button_click event is called when i refresh the page.
    so the problem is that when i refresh the page, the last action that i have
    done on the page is refired.
    if anybody can tell me how to solve this problem ill be thankfull...


  • Kevin Spencer

    #2
    Re: ASP.NET Refresh Problem

    You can't exactly solve it. What you can do is to handle it on the server.
    For example, you could set a Session variable when the insert occurs, and
    check it before doing the insert. If the Session variable is there, you know
    the record has been inserted already. Of course, you have to remove the
    Session variable at some point in order to do another insert. But of course,
    there are ways of doing that as well. There are other solutions as well. How
    you handle it is up to you, based upon the functionality of your page, and
    your creativity.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    All hotels in Benidorm. The best selection of Benidorm hotels with reviews and maps. Book in advance and save.

    Big Things are made up of
    Lots of Little Things.

    "wright" <yliu@wintech-soft.com> wrote in message
    news:eHZeFf6lDH A.3320@tk2msftn gp13.phx.gbl...[color=blue]
    > hello, i have a problem in refreshing a page. the problem happens when i
    > click a button that does a certain action in a web page, such as inserting[/color]
    a[color=blue]
    > record into the database, if now i refresh the page (press f5), the action
    > repeats itself and another identical record is inserted too.
    > i discovered that the button_click event is called when i refresh the[/color]
    page.[color=blue]
    > so the problem is that when i refresh the page, the last action that i[/color]
    have[color=blue]
    > done on the page is refired.
    > if anybody can tell me how to solve this problem ill be thankfull...
    >
    >[/color]


    Comment

    • Kevin Spencer

      #3
      Re: ASP.NET Refresh Problem

      You can't exactly solve it. What you can do is to handle it on the server.
      For example, you could set a Session variable when the insert occurs, and
      check it before doing the insert. If the Session variable is there, you know
      the record has been inserted already. Of course, you have to remove the
      Session variable at some point in order to do another insert. But of course,
      there are ways of doing that as well. There are other solutions as well. How
      you handle it is up to you, based upon the functionality of your page, and
      your creativity.

      --
      HTH,

      Kevin Spencer
      Microsoft MVP
      ..Net Developer
      All hotels in Benidorm. The best selection of Benidorm hotels with reviews and maps. Book in advance and save.

      Big Things are made up of
      Lots of Little Things.

      "wright" <yliu@wintech-soft.com> wrote in message
      news:eHZeFf6lDH A.3320@tk2msftn gp13.phx.gbl...[color=blue]
      > hello, i have a problem in refreshing a page. the problem happens when i
      > click a button that does a certain action in a web page, such as inserting[/color]
      a[color=blue]
      > record into the database, if now i refresh the page (press f5), the action
      > repeats itself and another identical record is inserted too.
      > i discovered that the button_click event is called when i refresh the[/color]
      page.[color=blue]
      > so the problem is that when i refresh the page, the last action that i[/color]
      have[color=blue]
      > done on the page is refired.
      > if anybody can tell me how to solve this problem ill be thankfull...
      >
      >[/color]


      Comment

      • George Ter-Saakov

        #4
        Re: ASP.NET Refresh Problem

        The problem is that when you press F5 IE sends excatly same info to the
        server.
        And server can not distinguish between first request and second.

        The easiest thing is to redirect to the page (it could be the same page).

        George.

        "wright" <yliu@wintech-soft.com> wrote in message
        news:eHZeFf6lDH A.3320@tk2msftn gp13.phx.gbl...[color=blue]
        > hello, i have a problem in refreshing a page. the problem happens when i
        > click a button that does a certain action in a web page, such as inserting[/color]
        a[color=blue]
        > record into the database, if now i refresh the page (press f5), the action
        > repeats itself and another identical record is inserted too.
        > i discovered that the button_click event is called when i refresh the[/color]
        page.[color=blue]
        > so the problem is that when i refresh the page, the last action that i[/color]
        have[color=blue]
        > done on the page is refired.
        > if anybody can tell me how to solve this problem ill be thankfull...
        >
        >[/color]


        Comment

        • George Ter-Saakov

          #5
          Re: ASP.NET Refresh Problem

          The problem is that when you press F5 IE sends excatly same info to the
          server.
          And server can not distinguish between first request and second.

          The easiest thing is to redirect to the page (it could be the same page).

          George.

          "wright" <yliu@wintech-soft.com> wrote in message
          news:eHZeFf6lDH A.3320@tk2msftn gp13.phx.gbl...[color=blue]
          > hello, i have a problem in refreshing a page. the problem happens when i
          > click a button that does a certain action in a web page, such as inserting[/color]
          a[color=blue]
          > record into the database, if now i refresh the page (press f5), the action
          > repeats itself and another identical record is inserted too.
          > i discovered that the button_click event is called when i refresh the[/color]
          page.[color=blue]
          > so the problem is that when i refresh the page, the last action that i[/color]
          have[color=blue]
          > done on the page is refired.
          > if anybody can tell me how to solve this problem ill be thankfull...
          >
          >[/color]


          Comment

          Working...