Click here to Skip to main content
15,906,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have created a aspx page using C# and ASP.NET and have put a button on it. And in the Click event of this button if i am inserting some data in database , after click if user refresh the page than click event gets fired again resulting data insertion to database again, to stop events on the page getting fired on browser refresh
which code i have to put in my page?
Posted

Have a look at this article. This should help you out in handling the issue you are facing: Refresh Page Issue in ASP.Net[^]

This is one of the various ways it was done. Others could be to verify the data entered last, compare and prompt before moving ahead.
 
Share this answer
 
Comments
Vigneshb6 28-Dec-10 4:20am    
nice one
Try:

if(!IsPostBack){
//Code to insert
}
 
Share this answer
 
Comments
Manfred Rudolf Bihy 28-Dec-10 4:02am    
Good call!
Sandeep Mewara 28-Dec-10 4:15am    
Sorry! but I don't agree with the solution. Page refresh follows the exact same route. Further, it's a button click event that is being triggered and will trigger again if refreshed. Putting it in IsPostback would not help. You can try that out.
You can use one of following solutions to solve this problem
1. After Upload is sucessfull. Response.Redirect to same page.
2. Use Javascript to disable F5 and right click.(User can still refresh from toolbar/menubar)
3. Use hiddenfield to check whether request came from buttonclick or refresh button
 
Share this answer
 

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