Click here to Skip to main content
15,911,039 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i am inserting values in database on click of the button. after that when i refresh the page it again inserts the values in database. i dont want this to happen.
Posted
Comments
Nelek 18-Oct-13 7:44am    

 
Share this answer
 
Comments
Harpreet_125 18-Oct-13 7:23am    
didnt work..
thatraja 18-Oct-13 10:28am    
Without showing your code, we can't even guess anything. Your reply "didnt work.." won't help both you & us
Quote:
All server-side events that get fired on the post-back get fired on refresh also, but fortunately there exists one event, onsubmit, that only gets fired when there is a genuine post-back request. It is the client-side event of the form placed on your web page.
 
Share this answer
 
Hi,

After any event, if you refresh page then it prompt for it and if we allow it it redo last event.

Now in your situation you are inserting values in db. So on refreshing page again your db insert query fires and it insert value in db.

Now you have two ways to over come this.
1. After inserting db value redirect to same page.
C#
e.g. //your db code
     Response.Redirect(Request.Url.AbsoluteUri);

2. In your db query, first check for value, if same value exist stop inserting in db.

Hope it helps you.
Thanks.
 
Share this answer
 
Comments
Tom Marvolo Riddle 18-Oct-13 8:58am    
@Harshil_raval:Above Code will work.But it will not show the alert message something like "Saved" or "updated" when i place such alert after this.Am i right?
Harshil_Raval 18-Oct-13 9:24am    
Yes, it will not. But if do some trick then we can do it. say for example, before redirect code save one flag value in session. Then on page load check if session is not null, then print relevant message, then remove session.
Are you with me now?
Tom Marvolo Riddle 19-Oct-13 0:35am    
Yes.Thank you
 
Share this answer
 
Comments
Harpreet_125 18-Oct-13 7:22am    
didnt work..
Tom Marvolo Riddle 18-Oct-13 7:43am    
Which one?Post your Code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900