Slide 11.13: Performing page navigation (scenario 1)
Slide 11.15: Performing page navigation (scenario 1) (cont.)
Home

Performing Page Navigation (Scenario 1) (Cont.)


The previous program calls the page, Controls_NavigationTarget.aspx, and sends a query string at the same time, for example,
   Controls_NavigationTarget_cs.aspx?name=Adam
A typical URL containing a query string is as follows:
   http://server/path/program?query_string
When a server receives a request for such a page, it runs a program, passing the query_string unchanged to the program. The question mark is used as a separator and is not part of the query string. For each field of the Web form, the query string contains a pair field=value. By using the method of query_string, a page can send data to another page. For the previous slide, the page Controls5_cs.aspx used the query_string “name=Adam” to the page Controls_NavigationTarget_cs.aspx, which retrieves the value Adam by using the Request.QueryString collection.


Controls_NavigationTarget_cs.aspx?name=Adam

Web
01<%@ Page Language="C#" AutoEventWireup="true"
02  CodeBehind="Controls_NavigationTarget_cs.aspx.cs"
03  Inherits="WebApplication11.Controls_NavigationTarget_cs" %>
04 
05<script language="C#" runat="server">
06 protected void Page_Load( object sender, EventArgs e ) {
07  if ( !Page.IsPostBack )
08   NameLabel.Text =
09     Server.HtmlDecode( Request.QueryString["Name"] );
10 }
11</script>
12 
13<html xmlns="http://www.w3.org/1999/xhtml" >
14 <body>
15  <h3><font face="Verdana">Handling Page Navigation</font></h3>
16  This sample demonstrates how to receive a navigation
17  request from another page, and extract the
18  querystring argument within the Page_Load event.
19  <hr />
20  <form runat="server">
21   <font face="Verdana">
22    Hi <asp:label id="NameLabel" runat="server" />!
23   </font>
24  </form>
25 </body>
26</html>