<span style="font-size:18px;">using System; using System.Web.UI; namespace WebApplication1 { public partial class List : Page { protected void Page_Load(object sender, EventArgs e) { // Get response. var response = base.Response; // Redirect temporarily. // ... Don't throw an HttpException to terminate. response.Redirect("http://www.jb51.net", false); } } } </span>
<span style="font-size:18px;">HTTP/1.1 302 Found Content-Type: text/html; charset=utf-8 Location: http://www.jb51.net Server: Microsoft-IIS/7.0 Date: Fri, 13 Aug 2010 21:18:34 GMT Content-Length: 144 <html><head><title>Object moved</title></head><body> <h2>Object moved to <a href="http://www.dotnetperls.com/list">here</a>.</h2> </body></html></span>
<span style="font-size:18px;">private void Button1_Click (object sender, System.EventArgs e) { Server.Transfer("webform2.aspx"); } </span>
4、创建过程来返回TextBox1,TextBox2控件的值
代码如下:
<span style="font-size:18px;">public string Name { get { return TextBox1.Text; } } public string EMail { get { return TextBox2.Text; } } </span>
<span style="font-size:18px;">private void Page_Load (object sender, System.EventArgs e) { //创建原始窗体的实例 WebForm1 wf1; //获得实例化的句柄 wf1=(WebForm1)Context.Handler; Label1.Text=wf1.Name; Label2.Text=wf1.EMail; } </span>
<span style="font-size:18px;"><%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebForm1.aspx.cs" Inherits="WebForm1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> </div> </form> </body> </html> </span>
<span style="font-size:18px;">using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class WebForm1 : System.Web.UI.Page { public string Time { get { return DateTime.Now.ToString(); } } public string TestFun() { return "Function of WebForm1 Called"; } protected void Page_Load(object sender, EventArgs e) { Context.Items.Add("Context", "Context from Form1"); } protected void Button1_Click(object sender, EventArgs e) { //this.TextBox2.Text =Request ["TextBox1"].ToString (); Server.Transfer("WebForm2.aspx", true);//第二个参数为false时,WebForm2.aspx中不能获得TextBox1的内容 } } </span>
得到一个302应答,第二次是请求302应答中声明的新页面,得到重定向之后的页面。
必须把目标页面Page指令的EnableViewStateMac属性设置成False。
被调用页面Page指令的EnableViewStateMac属性设置成False。
原窗口保留,另外新增一个新页面。
打开新的页面,原窗口被代替。
6.Response.Write("<script>window.showModalDialog('Default2.aspx')</script>");