zoukankan      html  css  js  c++  java
  • 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"]);
                }
            }
        }

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

  • 相关阅读:
    nohup ./startWebLogic.sh >out.log 2>&1 & 解析
    Eclipse debug 断点不能调试 ,Eclipse Unable to install breakpoint in 解决办法
    Servlet工作原理解析(tomcat7、嵌入式服务器)
    Servlet工作原理
    [Java] SpringMVC工作原理之四:MultipartResolver
    SQLite_安装
    leetcode_315_逆序对问题
    git 学习 3
    dubbo与zookeeper
    Kafka安装
  • 原文地址:https://www.cnblogs.com/lmfeng/p/2084311.html
Copyright © 2011-2022 走看看