Click to See Complete Forum and Search --> : Back Button Event?
modernthinker
Sep 6th, 2005, 08:45 AM
Hi,
Is it possible to add an event to a button on a web form so when it is clicked it goes back to the previous page. So it simply replicates the back button you find on a explorer browser. I want this so i can have all the values in a form still entered, i know i could do this using sessions etc but it would be much simplier to have that back button?
Thanks
dj4uk
Sep 6th, 2005, 09:01 AM
You redirect to the referrer page which does the same thing.
void button_click(object sender, EventArgs e) {
Response.Redirect(Request.UrlReferrer.ToString());
}
HTH
DJ
modernthinker
Sep 6th, 2005, 09:14 AM
Using a Response.Redirect method will cause my form fields to be empty once the button is clicked. But with a Browser back button, you still have your data on the original page?
dj4uk
Sep 6th, 2005, 09:20 AM
In which case you'd have to use client-side JavaScript to actually use the browser's history.
I believe the JavaScript needed is: history.go(-1).
DJ
Wokawidget
Sep 6th, 2005, 09:39 AM
This would look like:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Button1.Attributes.Add("onClick", "history.back();")
End Sub
Alnernatively you can do this at design time:
<asp:Button id="Button1" OnClick="history.back();" runat="server" Text="Button"></asp:Button>
Woof
modernthinker
Sep 6th, 2005, 09:51 AM
Thanks for that, the javascript works but one problem, i have autoPostback dropdownlists on the form page, so when i get back to the form page they aren't working properly. I will probably just do it using sessions variables to re-populate the data page.
Thanks!
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.