• 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);}
  • 相关阅读:
    创建索引
    异常处理之ThreadException、unhandledException及多线程异常处理
    Extjs ComboBox常用的配置
    制作Visual Studio项目模板
    wince更改桌面
    创建链接服务器
    IP查询接口
    软件工程未来发展趋势
    在SQL Server数据库开发中的十大问题
    .NET 2.0中的企业库异常处理块
  • 原文地址:https://www.cnblogs.com/9421/p/1634260.html
Copyright © 2020-2023  润新知