zoukankan      html  css  js  c++  java
  • ASP.net参数传递总结

    同一页面.aspx与.aspx.cs之间参数传递
    1. .aspx.cs接收.aspx的参数:由于.aspx和.aspx.cs为继承关系,所以.aspx.cs可以直接对.aspx中的ID进行值提取,具体语句为string b = a.text; 其中a为.aspx中的文本框的ID;
    2. .aspx接收.aspx.cs的变量:将.aspx.cs的变量设为全局变量,在.aspx中直接引用<%=a %>,这里a为.aspx.cs
    中声明的全局变量;
     
     
     不同页面之间的参数传递
    1.URL传递参数方法,有两种方法:
      第一种:send.aspx
                 <a href=receive.aspx?a=b></a>
                      receive.aspx.cs
                string c = Request.QueryString["a"];
      第二种:send.aspx.cs:
      protected void Button1_Click(object sender, EventArgs e)
        {
            Request.Redirect("receive.aspx?a=b");
        }
                     receive.aspx.cs:
      string username = Request.QueryString["username"];
    2. Form表单POST方法
    send.aspx
    <form id="form1" runat="server" action="receive.aspx" method=post>
        <div>
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
            <asp:TextBox ID="a" runat="server"></asp:TextBox>
       </div>
        </form>
    receive.aspx.cs
    string b = Ruquest.Form["a"];
    3.通过session方法传递参数
    send.aspx.cs:
      protected void Button1_Click(object sender, EventArgs e)
        {
            Session["username"] = "a";
            Request.Redirect("receive.aspx");
        }
     receive.aspx:
     string username = Session["username"];
  • 相关阅读:
    编程爱好者论坛第六次编程比赛题目
    google china code jam round2 div1 1000分题
    ogl2dlibsdl cvs repository @ cosoft
    偶尔也提一个游戏点子:宇宙碰撞
    今天看到一些笑话...
    google china code jam入围赛的一个题
    用Regular expression寻找源代码中的汉字字符串
    生成函数理论初步
    Komodo 的中文支持
    “豪华版”的USB延长线
  • 原文地址:https://www.cnblogs.com/Ghazi/p/6000432.html
Copyright © 2011-2022 走看看