页面间传值的方法?

 

今天参加了个面试一共9道题
1:页面间传值的方法?
 
<1>通过QueryString[GET]方式
    这种方式一般传递安全性不高的简单类型,像Array,Object就不可以传递
    Server.Transfer,Server.Execute()
    Response.Redirect()
    例如:
  
string url="http://www.baidu.com?UserName="+this.UserName.Text;
 
<2>使用Application全局变量
    例如:
  Application.Lock();
  Application[
"UserName"]="Roboth";
  Application.UnLock();

 
<3>使用Session
     例如:
  Session.Add(
"UserName","Roboth");
 
<4>使用Cookie
  HttpCookie cookie
=new HttpCookie("UserName");
  cookie.Value
="Roboth";
  Response.AppendCookie(cookie);
  
 
<5>Server.Transfer
 例如:
  a.aspx的C#代码
  
public string Name
  
{
      
getreturn Label1.Text;}
  }

  
private void Button1_Click(object sender, System.EventArgs e)
  
{
      Server.Transfer(
"b.aspx");
  }


  b.aspx中C#代码
  
private void Page_Load(object sender, EventArgs e)
  
{
      a newWeb;   
//实例a窗体
      newWeb = (source)Context.Handler;
      
string name;
      name 
= newWeb.Name;
  }


 
<6>Cache
  例如:
  Cache[
"prompt"]="Welcome to Olympic's Games"
    

 
posted @ 2007-08-22 21:43  roboth  阅读(276)  评论(0)    收藏  举报