2014/08/21

ASP.Net 取得Get字串

最近案子用ASP.Net做的,所以寫一下筆記,以免忘記XD

About.aspx
<%@ Page Title="關於我們" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="About.aspx.cs" Inherits="WebApplication1.About" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
        關於
    </h2>
    <div  runat=server id="AboutContent"></div>
</asp:Content>

透過Request的QueryString就可以得知Get字串

About.aspx.cs
using System;

namespace WebApplication1
{
    public partial class About : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            String test1 = Request.QueryString["Test1"];
            String test2 = Request.QueryString["Test2"];
            AboutContent.InnerHtml = test1 + test2;
        }
    }
}



執行結果: