Reputation: 119
I have insert page - data is getting inserted properly with all validations .But the main problem is that after insert if anyone clicks on the refresh button on the Internet explorer browser , data gets inserted again the same data which insert on submit button .
Thanks, Smartdev
Upvotes: 0
Views: 715
Reputation: 1
Dear User u have to use below code in the previous page to avoid back button work.
example...
suppose your page 1 is=x.jsp and page 2 is y.jsp
to restrict x.jsp when u click on y.jsp back button you have to add this code in x.jsp
<SCRIPT type="text/javascript">
window.history.forward();
function noBack() { window.history.forward(); }
</SCRIPT>
</HEAD>
<BODY onload="noBack();"
onpageshow="if (event.persisted) noBack();" onunload="">
Upvotes: 0
Reputation: 4702
A redirect would work. You can use something like this:
protected void Page_Load(object sender, EventArgs e)
{
if(dataWasInserted)
Response.Redirect("~/TheSamePage.aspx");
}
Upvotes: 0
Reputation: 4702
You can add code to your stored procedure that checks the database before the insert. If the data already exists that you are trying to avoid, do not execute the insert.
If you really want to allow intentional repetition of data, but not via accidental refreshes, you can use your timestamp to help determine if it was a recent duplicate that you want to block. Hopefully, though, you don't want duplicate data in your database at all, so I don't recommend that approach.
Upvotes: 0
Reputation: 13511
Do a redirect after you successfully perform the insert and this should not happen. Otherwise, you'll have to perform some process yourself to make sure it doesn't happen (perhaps use state management to set a "Has been saved" flag or something).
Upvotes: 1