现在的位置: 首页 > 综合 > 正文

asp.net 提交表单实例

2013年02月01日 ⁄ 综合 ⁄ 共 1292字 ⁄ 字号 评论关闭

新建一个Html页,一定要Html页:

<form action="jiaocheng2.aspx" method="get" > //把表单的值传给jiaocheng2.aspx 方式为get
    Name:<input id="name" name="name" type="text" /><br/>
    Password<input id="psd" name="psd" type="text" /><br/>
    <input id="Submit1" type="submit" value="submit" />
    </form>

jiaocheng2.aspx页:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class jiaocheng2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        string sname = Request["name"].ToString();
        string spsd = Request["psd"].ToString();

        string sname = Request.Form.Get("name").ToString();
        string spsd = Request.Form.Get("psd").ToString();

        string sname = Request.QueryString["name"].ToString();
        string spsd = Request.QueryString["psd"].ToString();

        //用这三种方式都可以接收表单 当表单传递方式为get时 第二种方式不能接收
        Response.Write(sname+"<br/>"+spsd);
     
    }
}

 

post与get的区别

1.Post传输数据时,不需要在URL中显示出来,而Get方法要在URL中显示。
2.Post传输的数据量大,可以达到2M,而Get方法由于受到URL长度的限制,只能传递大约1024字节.
3.Post顾名思义,就是为了将数据传送到服务器段,Get就是为了从服务器段取得数据.而Get之所以也能传送数据,只是用来设计告诉服务器,你到底需要什么样的数据.Post的信息作为http请求的内容,而Get是在Http头部传输的。

抱歉!评论已关闭.