笨笨乐园

ASP.NET如何实现页面间的参数传递

一.使用QueryString
 
源页面代码:
private void Button1_Click
(object sender, System.EventArgs e)
{
Response.Redirect("WebForm2.aspx?code="+this.TextBox1.Text+"&name="+this.TextBox2.Text);
}

或在源页面.aspx文件中:
<script language="javascript">
   function grdResult_CellClickHandler(gridName, cellId, button)
     {
       window.location="BOMItem.aspx?Code="+cell.Row.getCell(2).getValue();
     }
</script>

目标页面代码:
private void Page_Load
(object sender, System.EventArgs e)
{
this.Label1.Text = "code:"+this.Request.QueryString["code"]+" and name:"+this.Request.QueryString["name"];
}
 
二.使用Session变量

源页面代码:
private void Button1_Click
(object sender, System.EventArgs e)
{
   this.Session["code"] = this.TextBox1.Text;
   this.Session["name"] = this.TextBox2.Text;
   this.Response.Redirect("WebForm2.aspx");
}

目标页面代码:
private void Page_Load
(object sender, System.EventArgs e)
{
   this.Label1.Text = "code:"+this.Session["code"].ToString() +" and name:"+ this.Session["name"].ToString();
   this.Session.Remove("code");
   this.Session.Remove("name");
}
 
三.使用Server.Transfer
 
源页面代码:
把以下的代码添加到页面中
  public string code
  {
     get
        {
            return this.TextBox1.Text;
        }
  }

  public string name
  {
      get
         {
            return this.TextBox2.Text;
         }
  }


然后调用Server.Transfer方法
private void Button1_Click
(object sender, System.EventArgs e)
{
Server.Transfer("WebForm2.aspx");

}


目标页面代码:
private void Page_Load
(object sender, System.EventArgs e)
{
   WebForm1 wf1 = (WebForm1)Context.Handler;
   this.Label1.Text = "code:"+wf1.code +" and name:"+ wf1.name;

}

posted on 2006-07-26 14:52  Angus  阅读(790)  评论(2)    收藏  举报

导航