方式1:
在接收頁 的html代碼里加上一行: <%@ reference page = "webform1.aspx" %>
webform1 fp=(webform1)context.handler;
this.textbox1.text=fp.name; //name 是第一頁的public變量
context 提供對整個當前上下文(包括請求對象)的訪問。您可以使用此類共享頁之間的信息。
方式2:get方式
在發送頁
public int sum=0;
int i =int.parse(this.textbox1.text)*2;
server.transfer("webform2.aspx?sum="+i);
接收頁
this.textbox1.text=request["sum"].tostring();
or this.textbox1.text=request.params["sum"].tostring();
this.textbox1.text=request.querystring["sum"];
方法3:全局變量
發送頁:
application["sum"]=this.textbox1.text;
server.transfer("webform2.aspx");
接收頁:
this.textbox1.text=(string)application["sum"];
application實質上是整個虛擬目錄中所有文件的集合,如果想在整個應用范圍內使用某個變量值,application對象將是最佳的選擇
方法4:
發送頁:
1.定義靜態變量: public static string str="";
2. str=this.textbox1.text;
server.transfer("webform2.aspx");
接收頁:
1.引入第一頁的命名空間:using webapplication1;
2 this.textbox1.text=webform1.str;