zoukankan      html  css  js  c++  java
  • web程序设计(4)....页面间参数传递

    一:用过的:

    (1)通过URL链接地址传递 (加?..多个参数时加&para2=value中间不能有空格如href="receive.aspx?username=honge&pwd=123")

    send.aspx:
            //或者页面<a href="receive.aspx?username=honge"></a>
            protected void Button1_Click(object sender, EventArgs e)
            {     Request.Redirect("receive.aspx?username=honge"); }
    receive.aspx:
                string username = Request.QueryString["username"];这样可以得到参数值。
    ps1:传递的参数默认都是string类型,所以不必加引号,也不必类型转换后传递,在接收方为string类型.<汉字除外>

    ps2:当传递多个参数时,用&隔开,注意不能有空格

    ps3:当传递汉字时,常常先进行类型转换, System.Web.HttpUtility.UrlEncode("你好!");

    (2) 通过session
    send.aspx:
            protected void Button1_Click(object sender, EventArgs e)
            { Session["username"] = "honge"; Request.Redirect("Default2.aspx"); }
    receive.aspx:
             string username = Session["username"];     这样可以得到参数值。

    (3)通过cook:

    send:
        Request.Cookies.Add(new HttpCookie("cookie_stop2_class","education"));
    receive:
        HttpCookie myCook = Request.Cookies["cookie_stop2_class"];
        if(myCook!= null){
            string str =myCook.Value;  //str = education;

        }

     
    (4)通过Application
    send.aspx:
             protected void Button1_Click(object sender, EventArgs e)
             { Application["username"] = "honge"; Request.Redirect("Default2.aspx"); }
    receive.aspx: string username = Application["username"];这样可以得到参数值。

    (5)通过Server.Transfer
    send.aspx:
             public string Name { get { return "honge"; } }
             protected void Button1_Click(object sender, EventArgs e)
             { Server.Transfer("Default2.aspx"); }
     receive.aspx:
             send d = Context.Handler as send ;
             if (d != null) { Response.Write(d.Name);}
  • 相关阅读:
    递归和this指向
    作用域,闭包
    三种存储方式
    事件流,冒泡,捕获,事件委托
    centos添加登陆成功提示消息
    centos7下安装oracle11g R2报错
    linux下从home分区扩展到根分区
    linux下搭建mongodb副本集
    linux服务下使用nginx之后数据导出超时
    linux下搭建git服务器
  • 原文地址:https://www.cnblogs.com/9421/p/1634260.html
Copyright © 2011-2022 走看看