javascript - ASP.NET prevent browser 'back' -


i'm trying find solution problem i'm facing asp.net application (c# / mysql backend).

the application uses webforms in multi step wizard insert data sql database, various steps javascript driven no 'submit' done until 'last' step. in circumstances anyway if user click browser 'back' button after 'last' step form resubmitted , sql insert triggered again creating dupes of original record.

i tought use ajax based mechanism track steps of form until wizard reach 'last' step. after trough same ajax function prevent resubmit of form preventing dupes.

i don't want use javascript tricks disable button obvious reasons.

the main problem of solution don't , quite difficult implement since wizards on application form quite articulated , may cause problem.

is there 'best practice' prevent such issues without building complex infrastructures?

i'm not posting code because think misleading , unnecessary.

best regards, mike

i found solution problem. think can reasonably practice people facing same problem. of course it's not perfect maybe else can refine 'perfect solution'.

first of in .aspx code of page launching form duplicating records placed this:

<asp:linkbutton     id="_btnform1"     runat="server"     oncommand="link_command"     commandargument='<%#eval("id","~/form1.aspx?id={0}&step=exit")%>'>     form1 </asp:linkbutton> 

in backend code created hanlder link_button command:

protected void link_command(object sender, commandeventargs e) {     session["key"] = guid.newguid().tostring().replace("-", string.empty);      response.redirect(e.commandargument.tostring()); } 

in short generates unique hash code storing session value.

in form managing records checked session["key"] value present , not null. if key present code hasn't reached it's critical part forms should resubmitted without problems.

when code reaches critical part (just before data insertion database) cleared session["key"] value:

session.remove("key"); 

then if user tries resubmit form after critical part session key isn't present anymore , code trap 'anomaly' , show error message or redirect on different page:

if (session["key"] == null) {       response.redirect("error.aspx?script=" + httputility.urlencode(request.path)); } 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -