ASP.Net中Form表单的get和post的区别
< form id="form1" method="get" runat="server">
< div>
你的名字< asp:TextBox ID="name" runat="server">< /asp:TextBox>< br />
< br />
你的网站< asp:TextBox ID="website" runat="server">< /asp:TextBox>< br />
< br />
< br />
< asp:Button ID="Button1" runat="server" Text="send" />< br />
< br />
< br />
学习request 和 response的用法< br />
< br />
< br />
< /div>
< /form>
< form id="form2" method="post" runat="server">
< div>
你的名字< asp:TextBox ID="name2" runat="server">< /asp:TextBox>< br />
< br />
你的网站< asp:TextBox ID="website2" runat="server">< /asp:TextBox>< br />
< br />
< br />
< asp:Button ID="Button2" runat="server" Text="send" />< br />
< br />
< br />
学习request 和 response的用法< br />
< br />
< br />
< /div>
< /form>
/*从URL中可看出ASP.NET Get和Post的区别.那么那如何编程实现数据的接收呢?
第1种,接收用get 方法传输的数据的写法:
*/
protected void Page_Load(object sender, EventArgs e)
{
string id = Request.QueryString["name"];
string website = Request.QueryString["website"];
Response.Write(id + "< br>" + website);
Response.Write("你使用的是" + Request.RequestType + "方式传送数据");
}
//第2种,接收用post 方法传输的数据的写法:
protected void Page_Load(object sender, EventArgs e)
{
string id2 = Request.Form["name2"];
string website2 = Request.Form["website2"];
Response.Write(id2 + "< br>" + website2);
Response.Write("你使用的是" + Request.RequestType + "方式传送数据");
}
string id4 = Request["name4"];
string website4 = Request["website4"];
Response.Write(id4 + "< br>" + website4);
//第3种,同时接受get和post 方法传送数据的代码写法:
//A 写法
string id3 = Request.Params["name3"];
string website3 = Request.Params["website3"];
Response.Write(id3 + "< br>" + website3);
//B 写法
string id4 = Request["name4"];
string website4 = Request["website4"];
Response.Write(id4 + "< br>" + website4);