比如从test1.aspx页面点击按钮进入test2.aspx页面,如果想在test2.aspx页面中得到test1.aspx页面中某些控件的值.
test1.aspx前台代码, 这里要注意的按钮一定要设置postbackurl="test2.aspx" 属性,不能在它的CS代码中比如用Redirect 的方法


1


<%

@ Page Language="C#" AutoEventWireup="true" CodeFile="test1.aspx.cs" Inherits="Print_test1" %>
2

3

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4

5

<html xmlns="http://www.w3.org/1999/xhtml" >
6

<head runat="server">
7

<title>无标题页</title>
8

</head>
9

<body>
10

<form id="form1" runat="server">
11

<div>
12

<asp:TextBox ID="TextBox1" runat="server" Text="初值:sadfasdf"></asp:TextBox>
13

<asp:Button ID="Button1" runat="server" Text="Button" postbackurl="test2.aspx" /></div>
14

</form>
15

</body>
16

</html>
17

test1.aspx.cs //这个页面没写代码


1

using System;
2

using System.Data;
3

using System.Configuration;
4

using System.Collections;
5

using System.Web;
6

using System.Web.Security;
7

using System.Web.UI;
8

using System.Web.UI.WebControls;
9

using System.Web.UI.WebControls.WebParts;
10

using System.Web.UI.HtmlControls;
11

12

public partial class Print_test1 : System.Web.UI.Page
13



{
14

protected void Page_Load(object sender, EventArgs e)
15


{
16

}
17

}
18

test2.aspx 前台代码 //这里也没写什么东东


1


<%

@ Page Language="C#" AutoEventWireup="true" CodeFile="test2.aspx.cs" Inherits="Print_test2" %>
2


<%

@ PreviousPageType VirtualPath="test1.aspx" %>
3

4

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5

6

<html xmlns="http://www.w3.org/1999/xhtml" >
7

<head runat="server">
8

<title>无标题页</title>
9

</head>
10

<body>
11

<form id="form1" runat="server">
12

<div>
13
14

</div>
15

</form>
16

</body>
17

</html>
18

test2.aspx.cs


1

using System;
2

using System.Data;
3

using System.Configuration;
4

using System.Collections;
5

using System.Web;
6

using System.Web.Security;
7

using System.Web.UI;
8

using System.Web.UI.WebControls;
9

using System.Web.UI.WebControls.WebParts;
10

using System.Web.UI.HtmlControls;
11

12

public partial class Print_test2 : System.Web.UI.Page
13



{
14

protected void Page_Load(object sender, EventArgs e)
15


{
16

//Response.Write(this.PreviousPage.FindControl("TextBox1"));
17

string txt = ((TextBox)this.PreviousPage.FindControl("TextBox1")).Text;
18

19

Response.Write(txt);
20

//(this.PreviousPage).test();
21

}
22

}
23

在test2.aspx.cs 代码中使用类似((TextBox)this.PreviousPage.FindControl("TextBox1")).Text 的方法来访问前页的属性或方法.