ASP.NET Refresh Problem

W

wright

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...
 
K

Kevin Spencer

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
http://www.takempis.com
Big Things are made up of
Lots of Little Things.
 
G

George Ter-Saakov

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top