ASP.NET(C#)返回上一页(后退)代码(转载)
ASP.NET(C#)返回上一页(后退)代码
2008-08-10 10:32
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["BackUrl"] = Request.UrlReferrer.ToString();
}
}
/// <summary>
/// 返回按钮点击事件
/// </summary>
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect(ViewState["BackUrl"].ToString());
}
另一种方法
在C# Web程序中,如为页面按钮写返回上一页代码
this.RegisterClientScriptBlock("E", "<script language=javascript>history.go(-2);</script>");
其中,history.go(-2),要写为-2,因在按钮事件触发前,已刷新一次页面,所以应是-2。
Response.Write("<script language=javascript>history.go(-2);</script>");
此处也要写为“-2”。跟直接写脚本的有所不同。
相关文档:
1. 打开新的窗口并传送参数:
传送参数:
response.write("<script>window.open(’*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"’)</script>")
接收参数:
string a = Request.QueryString("id");
string b = Request.QueryString("id1");
2.为按钮添加对话框
Button1 ......
1.什么是cookie?
cookie 是一小段文本信息,伴随用户请求,在web服务器和浏览器之间传递。用户每次访问站点的时候,
web应用程序都可以读取cookie包含的信息。
假设在用户请求您的网站的某个页面时,您的应用程序不仅是返回请求的页面。同时也返回一个包含日期
和时间的cookie。用户的浏览器在获得页面的同时也获得了 ......
using System;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.SessionState;
using System.Timers;
using System.Data;
using System.Data.SqlClient;
namespace SMS_joke
{
/// <summary>
/// Global 的摘要说明。
/// </summary>
public class ......