Code is reexecuted when the user clicks Refresh

Discussion in 'ASP .Net' started by Nathan Sokalski, Jan 19, 2007.

  1. I have a page which allows the user to send emails. After they click the
    submit button, I display a confirmation message. However, if the user clicks
    the browser's Refresh button once the confirmation message is displayed, the
    email is sent a second time (or a third, fourth, fifth, etc.). What can I do
    to prevent the Refresh button from resending the email? Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
     
    Nathan Sokalski, Jan 19, 2007
    #1
    1. Advertising

  2. Nathan Sokalski

    RSH Guest

    Nathan,

    You could set a session varaible that once the email was sent the session
    variable would be sent and you would add a wrapper to check for a value in
    the session variable before sending emails.

    If they hit the refresh button does that cause a postback...I'm not sure.
    If not, then you can simply check if the request is a postback...if it is
    send the email...else dont.

    HTH
    Ron


    "Nathan Sokalski" <> wrote in message
    news:%...
    >I have a page which allows the user to send emails. After they click the
    >submit button, I display a confirmation message. However, if the user
    >clicks the browser's Refresh button once the confirmation message is
    >displayed, the email is sent a second time (or a third, fourth, fifth,
    >etc.). What can I do to prevent the Refresh button from resending the
    >email? Thanks.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
     
    RSH, Jan 19, 2007
    #2
    1. Advertising

  3. Maybe Response.Redirect? That will flush out your POST headers to prevent
    the submit from happening repeatedly
     
    Keith Patrick, Jan 19, 2007
    #3
  4. Nathan Sokalski

    \(O\)enone Guest

    Keith Patrick wrote:
    > Maybe Response.Redirect? That will flush out your POST headers to
    > prevent the submit from happening repeatedly


    This is the approach we use. It works perfectly.

    --

    (O)enone
     
    \(O\)enone, Jan 19, 2007
    #4
  5. Nathan,

    You can try to set a session variable that tells that the post has been
    send.

    Cor

    "Nathan Sokalski" <> schreef in bericht
    news:%...
    >I have a page which allows the user to send emails. After they click the
    >submit button, I display a confirmation message. However, if the user
    >clicks the browser's Refresh button once the confirmation message is
    >displayed, the email is sent a second time (or a third, fourth, fifth,
    >etc.). What can I do to prevent the Refresh button from resending the
    >email? Thanks.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
     
    Cor Ligthert [MVP], Jan 20, 2007
    #5
  6. Nathan Sokalski

    Spam Catcher Guest

    "Nathan Sokalski" <> wrote in
    news:#:

    >
    > I have a page which allows the user to send emails. After they click
    > the submit button, I display a confirmation message. However, if the
    > user clicks the browser's Refresh button once the confirmation message
    > is displayed, the email is sent a second time (or a third, fourth,
    > fifth, etc.). What can I do to prevent the Refresh button from
    > resending the email? Thanks.


    Session variables, database flag, cookies - since the web is stateless,
    you'll need some sort of mechanism to track when the last request occured
    and if the current request is valid.
     
    Spam Catcher, Jan 20, 2007
    #6
    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. Guest
    Replies:
    1
    Views:
    413
    Michael Pearson
    Oct 30, 2003
  2. PontiMax

    Clicks and double-clicks

    PontiMax, Jul 14, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    186
    Eliyahu Goldin
    Jul 14, 2004
  3. Trint Smith

    Button clicks everytime I refresh screen???...

    Trint Smith, Feb 23, 2004, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    179
    Trint Smith
    Feb 24, 2004
  4. morc
    Replies:
    4
    Views:
    175
    Thomas 'PointedEars' Lahn
    Feb 14, 2006
  5. Badass Scotsman
    Replies:
    1
    Views:
    182
    Randy Webb
    Apr 27, 2006
Loading...

Share This Page