471,123 Members | 791 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,123 software developers and data experts.

How to prevent duplicate posting on a form w/ refresh?

This may be a very simple question but I'm stumped none the less.

I have a form where a user provides comments. There's a Grid below this
form which displays all comments in the table so far. On the Page_Load sub,
this grid is loaded. When they submit the form, a SaveComments Sub will
insert the record into a table and then disable the button and textbox
(greyed out) and display a message in a asp:label saying "thank you...".
The last step of the SaveComments Sub is to reload the Grid which will show
the user's newly provided comments to the list of other comments.

Simple enough.

The button is disabled so they can't submit comments a second time during
that session. But I've discovered that if you refresh/reload the page,
it'll run the Sub all over again....inserting another record each time you
reload the page and the duplicates start appearing in the Grid. D'oh!!

So how can I easily prevent this? The only solution I can come up with is to
redirect them to another confirmation page. Not what I was hoping for.....

I'm using VB as the base code.
Nov 19 '05 #1
4 4884
Now what if they come the next day to add the exact same comment ? How can
you prevent this ?

You have basically two visions here :
- either accept it, this is the exact semantic for refresh : it repeats the
last HTTP request meaning submitting again the same data if you were
submitting (and most browsers should display a warning)
- you could tweak your app to disallow this. Hard to say wihtout knowing
your app but it looks like you meant you accept a single comment by session
? You could then if the session is the same update the current record or
just discard the input.

My personal preference is rather 1 (especially if they can delete the
comments) unless it would cause something irreversible and.or harmfull (such
as ordering a second car or something like that).

Patrice

--

"D. Shane Fowlkes" <sh**********@h-o-t-m-a-i-l.com> a écrit dans le message
de news:%2****************@TK2MSFTNGP09.phx.gbl...
This may be a very simple question but I'm stumped none the less.

I have a form where a user provides comments. There's a Grid below this
form which displays all comments in the table so far. On the Page_Load sub, this grid is loaded. When they submit the form, a SaveComments Sub will
insert the record into a table and then disable the button and textbox
(greyed out) and display a message in a asp:label saying "thank you...".
The last step of the SaveComments Sub is to reload the Grid which will show the user's newly provided comments to the list of other comments.

Simple enough.

The button is disabled so they can't submit comments a second time during
that session. But I've discovered that if you refresh/reload the page,
it'll run the Sub all over again....inserting another record each time you
reload the page and the duplicates start appearing in the Grid. D'oh!!

So how can I easily prevent this? The only solution I can come up with is to redirect them to another confirmation page. Not what I was hoping for.....
I'm using VB as the base code.

Nov 19 '05 #2
As a general mechanism :
http://msdn.microsoft.com/asp.net/co...drockas_topic2

Patrice

--

"Patrice" <no****@nowhere.com> a écrit dans le message de
news:uJ****************@TK2MSFTNGP12.phx.gbl...
Now what if they come the next day to add the exact same comment ? How can
you prevent this ?

You have basically two visions here :
- either accept it, this is the exact semantic for refresh : it repeats the last HTTP request meaning submitting again the same data if you were
submitting (and most browsers should display a warning)
- you could tweak your app to disallow this. Hard to say wihtout knowing
your app but it looks like you meant you accept a single comment by session ? You could then if the session is the same update the current record or
just discard the input.

My personal preference is rather 1 (especially if they can delete the
comments) unless it would cause something irreversible and.or harmfull (such as ordering a second car or something like that).

Patrice

--

"D. Shane Fowlkes" <sh**********@h-o-t-m-a-i-l.com> a écrit dans le message de news:%2****************@TK2MSFTNGP09.phx.gbl...
This may be a very simple question but I'm stumped none the less.

I have a form where a user provides comments. There's a Grid below this
form which displays all comments in the table so far. On the Page_Load sub,
this grid is loaded. When they submit the form, a SaveComments Sub will insert the record into a table and then disable the button and textbox
(greyed out) and display a message in a asp:label saying "thank you...".
The last step of the SaveComments Sub is to reload the Grid which will

show
the user's newly provided comments to the list of other comments.

Simple enough.

The button is disabled so they can't submit comments a second time during that session. But I've discovered that if you refresh/reload the page, it'll run the Sub all over again....inserting another record each time you reload the page and the duplicates start appearing in the Grid. D'oh!!

So how can I easily prevent this? The only solution I can come up with

is to
redirect them to another confirmation page. Not what I was hoping

for.....

I'm using VB as the base code.


Nov 19 '05 #3
I love those payment screens that warn you not to click submit twice!

You might try something like this...

private bool SubmitWasClicked {
get { return (bool)ViewState["SubmitWasClicked"]; }
set { ViewState["SubmitWasClicked"] = value; }
}

private void Page_Load(object sender, System.EventArgs e) {
if ( ! this.IsPostBack ) {
SubmitWasClicked = false;
}
}

private void Submit_Click(object sender, System.EventArgs e) {
if ( ! SubmitWasClicked ) {
Label2.Text = "Submit was clicked for the first time.";
// TODO - Your processing goes here
SubmitWasClicked = true;
} else {
Label2.Text = "Nice Try!";
}
}

"D. Shane Fowlkes" wrote:
This may be a very simple question but I'm stumped none the less.

I have a form where a user provides comments. There's a Grid below this
form which displays all comments in the table so far. On the Page_Load sub,
this grid is loaded. When they submit the form, a SaveComments Sub will
insert the record into a table and then disable the button and textbox
(greyed out) and display a message in a asp:label saying "thank you...".
The last step of the SaveComments Sub is to reload the Grid which will show
the user's newly provided comments to the list of other comments.

Simple enough.

The button is disabled so they can't submit comments a second time during
that session. But I've discovered that if you refresh/reload the page,
it'll run the Sub all over again....inserting another record each time you
reload the page and the duplicates start appearing in the Grid. D'oh!!

So how can I easily prevent this? The only solution I can come up with is to
redirect them to another confirmation page. Not what I was hoping for.....

I'm using VB as the base code.

Nov 19 '05 #4
Don't mind me, that trick never works.

"Brad Quinn" wrote:
I love those payment screens that warn you not to click submit twice!

You might try something like this...

private bool SubmitWasClicked {
get { return (bool)ViewState["SubmitWasClicked"]; }
set { ViewState["SubmitWasClicked"] = value; }
}

private void Page_Load(object sender, System.EventArgs e) {
if ( ! this.IsPostBack ) {
SubmitWasClicked = false;
}
}

private void Submit_Click(object sender, System.EventArgs e) {
if ( ! SubmitWasClicked ) {
Label2.Text = "Submit was clicked for the first time.";
// TODO - Your processing goes here
SubmitWasClicked = true;
} else {
Label2.Text = "Nice Try!";
}
}

"D. Shane Fowlkes" wrote:
This may be a very simple question but I'm stumped none the less.

I have a form where a user provides comments. There's a Grid below this
form which displays all comments in the table so far. On the Page_Load sub,
this grid is loaded. When they submit the form, a SaveComments Sub will
insert the record into a table and then disable the button and textbox
(greyed out) and display a message in a asp:label saying "thank you...".
The last step of the SaveComments Sub is to reload the Grid which will show
the user's newly provided comments to the list of other comments.

Simple enough.

The button is disabled so they can't submit comments a second time during
that session. But I've discovered that if you refresh/reload the page,
it'll run the Sub all over again....inserting another record each time you
reload the page and the duplicates start appearing in the Grid. D'oh!!

So how can I easily prevent this? The only solution I can come up with is to
redirect them to another confirmation page. Not what I was hoping for.....

I'm using VB as the base code.

Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by martin1 | last post: by
2 posts views Thread by Harry Haller | last post: by
6 posts views Thread by Arthur Dent | last post: by
6 posts views Thread by teser3 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.