asp.net 页面传值方法

来源:互联网 发布:网页版股票行情软件 编辑:程序博客网 时间:2024/06/13 11:36

今天开始接着弄c#基础。

如题所示,讨论一下asp.net页面间传值的方式。目前只知道三种(页面跳转Response.Redirect(“url”))

1.QueryString 方式

页面A和页面B之间进行传值。

B.aspx?param1=***;param2=**;...


B页面: if (null != Request.QueryString["id"])
            {
                strMsg += @"          querystring传递的参数:" + Request.QueryString["id"] + @"";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "", "<script>alert('" + strMsg + "');</script>", false);
            }


2.Session【“”】

A页面

 Session["type"] = 1;
            Session["redirectName"] = "redirectName";
            Session["redirectSex"] = "redirectSex";
            Response.Redirect("ArguementTransfer.aspx?rname=1232;rsex=3333");

B页面

  if (Session["type"].ToString()=="1")
            {
                 string strMS = "redirectName 的值:" + Session["redirectName"];
            strMS += "           redirectSex 的值:" + Session["redirectSex"];
            TextBox1.Text = strMS;
            TextBox1.Width = 500;
            }


3.比较坑爹,用Server.Transfer(“url”)

需要把A整个页面以对象方式传给B。

A页面

  _strResult = n.ToString();
            Server.Transfer(url);



B页面

   #region Server.Transfer
            if (Session["type"].ToString()=="0")
            {
                 chapter1 c1;
            c1 = (chapter1)Context.Handler;
            string strResult = c1._strResult;
            TextBox1.Text = strResult;
            }
           
            #endregion




0 0
原创粉丝点击