Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Mimic the Browsers Back, Forward and Refresh buttons.


Message #1 by "David Garner" <dgarner@g...> on Tue, 11 Jun 2002 20:31:07
Hello,

The problem that you have is something that we deal with alot.
When the page loads you can use this code to store the back button effect.

	try
	{
		// Store URL Referrer to return to portal
		ViewState["UrlReferrer"] = Request.UrlReferrer.ToString();
	}
	catch (Exception ex)
	{
		ViewState["UrlReferrer"] = "defaulturl";
	}

Then handle the click of a button such as :-

    //**************************************************************
    //
    // The CancelBtn_Click event handler on this Page is used** to cancel
    // out of the page, and return the user back to the portal home
    // page.
    //
    //****************************************************************

    void CancelBtn_Click(Object sender, EventArgs e) {
        //Redirect back to the portal home page
        Response.Redirect((String) ViewState["UrlReferrer"]);
    }

In the page use :-

<asp:LinkButton id="CancelBtn" CausesValidation="false" OnClick="CancelBtn_Click" Text="Back To Page" runat="server" />


This should cover the Back button option.

For the refresh option simply create a link button with no OnClick handler.  This will cause the page to post back and re-load.

Of course this is limited to only one page going back, as the page loads it catches the URL of the page that you have just come from
and places that in the ViewState.  However it should be possible to alter the code to create a more extensive list. However we did
not need this functionality to include more than one page.

HTH

Aiden

-----Original Message-----
From: Philip Steel [mailto:PhilipS@t...]
Sent: 12 June 2002 17:14
To: ASPX_Professional
Subject: [aspx_professional] RE: Mimic the Browsers Back, Forward and
Refresh buttons.


No worries,

If you ever decide to have a look at C#, you'll find the syntax is very
similar to JavaScript
and indeed Java  ;-) 

Phil

-----Original Message-----
From: David Garner [mailto:dgarner@g...]
Sent: 12 June 2002 18:21
To: ASPX_Professional
Subject: [aspx_professional] RE: Mimic the Browsers Back, Forward and
Refresh buttons.


Thanks, I admit it freely that I'm trying to forget Java ever existed.  I 
have written several web applications in .Net and this will be the first 
time I've had to use Javascript.

If anyone does have the .Net solution (if it indeed exists) I'd be 
grateful to hear about it.

David Garner


  Return to Index