asp net 的form表单的提交

 下面是一个最简单的form表单,注意这里的action是关键,表示要提交的地址,

<form action="getpost.aspx" method="post">
          <input type="submit" ID="btnSearch" name="btnSearch" value="搜索" class="button btn" />
          <input id="txtsearchKey" name="txtsearchKey" class="text" value="<%=Request.QueryString["key"] %>" type="text" />
 </form>

getpost.aspx页面不用什么代码就一句话

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="getpost.aspx.cs" Inherits="getpost" %>

getpost.aspx.cs中代码如下:

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class getpost : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string searchword = Server.UrlEncode(Request.Form["txtsearchKey"]);
        Response.Redirect("expert.aspx?key=" + searchword);
    }
}

这里面就是表单的值的一个获取,并且通过Response.Redirect("expert.aspx?key=" + searchword);来传到expert.aspx页面,

在expert.aspx.cs文件Page_Load方法中用Request.QueryString["key"]方式获取信息:

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string Keyword = "";
            if (!string.IsNullOrEmpty(Request.QueryString["key"]))
            {
                Keyword = Server.UrlDecode(Request.QueryString["key"]);
            }
        }
    }

好了,这样就搞定了,讲的很细很细,不知道你看明白了没有。。。。。。

原文地址:https://www.cnblogs.com/lmfeng/p/2084311.html