ASP.NET Page类对象

request对象  

        ASP.NET Request对象功能是从客户端得到数据,可以读取从其他页面提交的数据,常用的三种取得数据的方法是:Request.Form(通过form表单提 交)、Request.QueryString(url?后面的参数),Request。其第三种是前两种的一个缩写,可以取代前两种情况。而前两种主要 对应的Form提交时的两种不同的提交方法:分别是Post方法和Get方法。

1、get方式

          protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["InputData1"] != null)
            Response.Write( Request.QueryString["InputData1"].ToString ());
        }
    }
    protected void GETSubmit_Click(object sender, EventArgs e)
    {
        Server.Transfer("GETPage.aspx?InputData1=" + InputData1.Text);
    }

使 用querystring获取get提交的时候不能直接使用 response.write(request.querystring["id"].tostring());会出现“未将对象引用设置到对象的实例” 错误,需要加一条语句if(request.querystring["id"]!=null]),原因是querystring获取的值不能为空。

2、post方式

protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            Response.Write(Request.Form["InputData"].ToString());
        }
    }

此时使用if(!ispostback)时,在点击提交按钮时无法执行Response.Write(Request.Form["InputData"].ToString());//未解决,未弄明白

posted @ 2013-03-11 16:30  天涯海角路  阅读(239)  评论(0)    收藏  举报