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
<%@ Page Language="C#" AutoEventWireup="true"
  CodeBehind="Controls_NavigationTarget_cs.aspx.cs"
  Inherits="WebApplication11.Controls_NavigationTarget_cs" %>

<script language="C#" runat="server">
 protected void Page_Load( object sender, EventArgs e ) {
  if ( !Page.IsPostBack )
   NameLabel.Text = 
     Server.HtmlDecode( Request.QueryString["Name"] );
 }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" > 
 <body>
  <h3><font face="Verdana">Handling Page Navigation</font></h3>
  This sample demonstrates how to receive a navigation
  request from another page, and extract the
  querystring argument within the Page_Load event.
  <hr />
  <form runat="server">
   <font face="Verdana">
    Hi <asp:label id="NameLabel" runat="server" />!
   </font>
  </form>
 </body>
</html>