一个服务器端的后退控件
// ?2003 IDesign Inc. All rights reserved
//Questions? Comments? go to
//http://www.idesign.net
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
namespace WebControlsEx
{
/// <summary>
/// Sends user to the URL of the client's previous request that linked to the current URL.
/// </summary>
[ToolboxData("<{0}:BackLink runat=server></{0}:BackLink>")]
[ToolboxBitmap(typeof(BackLink),"BackLink.bmp")]
public class BackLink : LinkButton
{
public BackLink()
{
Text = "Back";
ToolTip = "Click to go to the previous page";
}
protected override void OnClick(EventArgs e)
{
Uri backURL = (Uri)Page.Session["Referring URL"];
Page.Session["Referring URL"] = null;
if(backURL != null)
{
Page.Response.Redirect(backURL.AbsoluteUri);
}
}
protected override void OnLoad(EventArgs e)
{
Uri backURL = Page.Request.UrlReferrer;
if(backURL == null) //No referrer information
{
Enabled = false;
return;
}
if(backURL.AbsolutePath != Page.Request.Url.AbsolutePath)
{
Page.Session["Referring URL"] = backURL;
Enabled = true;
return;
}
else
{
object obj = Page.Session["Referring URL"];
if(obj != null)
{
Enabled = true;
}
}
base.OnLoad(e);
}
}
}
浙公网安备 33010602011771号