asp.net获取页面url参数值的实现代码实例

file: default.aspx.cs

using system;
using system.data;
using system.configuration;
using system.collections;
using system.web;
using system.web.security;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.webcontrols.webparts;
using system.web.ui.htmlcontrols;

public partial class querystringsender : system.web.ui.page
{
    protected void page_load(object sender, eventargs e)
    {

    }
  protected void cmd_click(object sender, eventargs e)
  {
    response.redirect("nextpage.aspx" + "?version=" +
        ((control)sender).id);
  }
}

file: nextpage.aspx

<%@ page language="c#"
         autoeventwireup="true"
         codefile="nextpage.aspx.cs"
         inherits="querystringrecipient" %>

<!doctype html public "-//w3c//dtd xhtml 1.1//en" "http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>untitled page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:label id="lbldate"
               runat="server"
               width="528px"
               height="112px"
               font-names="verdana"
               font-size="large"
               enableviewstate="false">
    </asp:label>
    </div>
    </form>
</body>
</html>

file: nextpage.aspx.cs

using system;
using system.data;
using system.configuration;
using system.collections;
using system.web;
using system.web.security;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.webcontrols.webparts;
using system.web.ui.htmlcontrols;

public partial class querystringrecipient : system.web.ui.page
{
    protected void page_load(object sender, eventargs e)
    {
    lbldate.text = "the time is now:<br>" + datetime.now.tostring();
    switch (request.querystring["version"])
    {
      case "cmdlarge":
        lbldate.font.size = fontunit.xlarge;
        break;
      case "cmdnormal":
        lbldate.font.size = fontunit.large;
        break;
      case "cmdsmall":
        lbldate.font.size = fontunit.small;
        break;
    }
    }
}

file: default.aspx

<%@ page language="c#" autoeventwireup="true" codefile="default.aspx.cs" inherits="querystringsender" %>

<!doctype html public "-//w3c//dtd xhtml 1.1//en" "http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>untitledwww.3ppt.com page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:button id="cmdlarge"
                runat="server"
                text="large text version"
                οnclick="cmd_click">
    </asp:button>
  <asp:button id="cmdnormal" runat="server" text="normal version" οnclick="cmd_click"></asp:button>
  <asp:button id="cmdsmall" runat="server" text="small text version" οnclick="cmd_click"></asp:button>
    </div>
    </form>
</body>
</html>