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 ......
在c# / ASP.net中我们可以通过使用DataTime这个类来获取当前的时间。通过调用类中的各种方法我们可以获取不同的时间:如:日期(2008-09-04)、时间(12:12:12)、日期+时间(2008-09-04 12:11:10)等。
//获取日期+时间
DateTime.Now.ToString(); // 2008- ......
在我们传统的网站建设中通常是先设计网站页面,再利用开发工具,在网站的框架内进行功能设计。这样的网站建设存在很多弊端,其中最突出的缺点是不利于小组共同开发,各环节之间依赖性太强。
在ASP.NET中我们可以利用后台编码,把HTML用户界面设计(颜色、美学等)与页面代码区分开来。这样就可以解决我们小组的并行开发问 ......
Asp.net 自动发送邮件的方法
今天有一个模块需要自动发送邮件的功能,就随便写了一个,记录一下作为积累。
一、首先需要配置web.config文件:
<system.net>
<mailSettings>
<smtp from="Emailname">
<network ho ......