1、QueryString
2、Application

Application对象的作用范围是整个全局,也就是说对所有用户都有效.其常用的方法用Lock和UnLock.

a.aspx的C#代码

private void Button1_Click( object sender, System.EventArgs e )
{

    Application["name"] = Label1.Text;

    Server.Transfer( "b.aspx" );

}

b.aspx中C#代码

private void Page_Load( object sender, EventArgs e )

{

    string name;

    Application.Lock( );

    name = Application["name"].ToString( );

    Application.UnLock( );

}

3、Session

4、Cookie

这个也是大家常使用的方法,与Session一样,其是什对每一个用户而言的,但是有个本质的区别,即Cookie是存放在客户端的,而session是存放在服务器端的.而且Cookie的使用要配合asp.NET内置对象Request来使用.

a.aspx的C#代码

private void Button1_Click( object sender, System.EventArgs e )
{

    HttpCookie cookie_name = new HttpCookie( "name" );

    cookie_name.Value = Label1.Text;

    Reponse.AppendCookie( cookie_name );

    Server.Transfer( "b.aspx" );

}

b.aspx中C#代码

private void Page_Load( object sender, EventArgs e )

{

    string name;

    name = Request.Cookie["name"].Value.ToString( );

}

5、Server.Transfer

虽然这种方法有点复杂,但也不失为一种在页面传值的方式。

  举个例子看看:

  1、创建一个web form

  2、在新建的web form中放置一个button1,在放置两个TextBox1,TextBox2

  3、为button按钮创建click事件

  代码如下:
  private void Button1_Click
  (object sender, System.EventArgs e)
  {
   Server.Transfer("webform2.aspx");
  }

  4、创建过程来返回TextBox1,TextBox2控件的值代码如下:
  public string Name
  {
   get
   {
    return TextBox1.Text;
   }
  }
  
  public string EMail
  {
   get
   {
    return TextBox2.Text;
   }
  }

  5、新建一个目标页面命名为webform2

  6、在webform2中放置两个Label1,Label2

  在webform2的Page_Load中添加如下代码:
  private void Page_Load
  (object sender, System.EventArgs e)
  {
   //创建原始窗体的实例
   WebForm1 wf1;
   //获得实例化的句柄
   wf1=(WebForm1)Context.Handler;
   Label1.Text=wf1.Name;
   Label2.Text=wf1.EMail;
  
  }
  运行,即可看到传递后的结果了。