码迷,mamicode.com
首页 > Web开发 > 详细

ASP.NET参数传递总结

时间:2014-08-23 17:40:11      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:os   io   strong   for   ar   div   cti   sp   on   

同一页面.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"];

ASP.NET参数传递总结

标签:os   io   strong   for   ar   div   cti   sp   on   

原文地址:http://www.cnblogs.com/jession/p/3931491.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!