2014年6月30日 星期一

ASP.NET Submit (使用POST、GET)

PostDemo.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PostDemo.aspx.cs" Inherits="PassValuesBetweenPages.PostDemo" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" method="post" action="PostDemo.aspx?p1=test456">
        <div>
            <input name="test" value="test123" type="text" />
            <input type="submit" value="送出" />    
        </div>
    </form>
</body>
</html>

PostDemo.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PassValuesBetweenPages
{
    public partial class PostDemo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Form["test"] != null)
            {
                string strTest = Request.Form["test"].ToString();
                string strP1 = Request.QueryString["p1"].ToString();
                Response.Write("test : " + strTest);
                Response.Write("p1 : " + strP1);
            }
        }
    }
}

沒有留言:

張貼留言