Linking Between ASP.NET Mobile Web Pages

If you have a link in the format #form1 in a control contained in a user control, the ResolveFormReference method looks in the user control for a form whose ID property is set to form1. If the form is not found, the method walks up the chain of nested user controls, and then searches for the form on the page. To link a form that is contained in a user control, use the following syntax to identify the form.

#mc1:form4

mc1 is the user control identifier. The colon (:) separates the reference to the form.

Note

There is no support for element anchors (URLs of the form page.aspx#element, where page is not the current page).

Example

The following code example demonstrates navigation between forms. The example contains a mobile Web page and a mobile user control.

Formtest.aspx

<%@ Page Language="C#" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" %>
<%@ Register TagPrefix="uc1" TagName="MobileWebUserControl1" 
    Src="formtest.ascx" %>
<script runat="server">
void Form_Activate(Object sender, EventArgs e)
{
    ((Form)sender).DataBind();
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
  <mobile:form id="Form1" runat="server" 
    OnActivate="Form_Activate">
    <mobile:Label ID="Label1" runat="server" 
        Text='<%# "Current: " + ActiveForm.UniqueID %>' />
    <mobile:Link ID="Link1" href="#form2" 
        runat="server">Go to Form 2</mobile:Link>
    <mobile:Link ID="Link2" href="#form3" 
        runat="server">Go to Form 3</mobile:Link>
    <mobile:Link ID="Link3" href="#mc1:form4" 
        runat="server">Go to Form 4</mobile:Link>
   /mobile:form>

  <mobile:Form ID="Form2" Runat="server" 
      OnActivate="Form_Activate">
    <mobile:Label ID="Label2" runat="server" 
        Text='<%# "Current: " + ActiveForm.UniqueID %>' />
    <mobile:Link ID="Link4" href="#form1" 
        runat="server">Go to Form 1</mobile:Link>
    <mobile:Link ID="Link5" href="#form3" 
        runat="server">Go to Form 3</mobile:Link>
    <mobile:Link ID="Link6" href="#mc1:form4" 
        runat="server">Go to Form 4</mobile:Link>
  </mobile:Form>

  <mobile:Form ID="Form3" Runat="server" 
      OnActivate="Form_Activate">
    <mobile:Label ID="Label3" Runat="server" 
        Text='<%# "Current: " + ActiveForm.UniqueID %>'>
    </mobile:Label>
    <mobile:Link ID="Link7" href="#form1"
        Runat="server" >Go to Form 1</mobile:Link>
    <mobile:Link ID="Link8" href="#form2"
        Runat="server" >Go to Form 2</mobile:Link>
    <mobile:Link ID="Link9" href="#mc1:form4"
        Runat="server" >Go to Form 4</mobile:Link>
  </mobile:Form>

  <uc1:MobileWebUserControl1 id="mc1" runat="server" />
</body>
</html>

Formtest.ascx

<%@ Control Language="C#" ClassName="FormTest" 
    Inherits="System.Web.UI.MobileControls.MobileUserControl" %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" %>

<script runat="server">
void Form_Activate(Object sender, EventArgs e)
{
    ((Form)sender).DataBind();
}
</script>

<mobile:Form ID="Form4" Runat="server" OnActivate="Form_Activate">
  <mobile:Label ID="Label1" runat="server" 
      Text='<%# "Current: " + 
        ((MobilePage)Page).ActiveForm.UniqueID %>' />
  <mobile:Link ID="Link1" href="#form1" 
      runat="server">Go to Form 1</mobile:Link>
  <mobile:Link ID="Link2" href="#form2" 
      runat="server">Go to Form 2</mobile:Link>
  <mobile:Link ID="Link3" href="#form3" 
      runat="server">Go to Form 3</mobile:Link>
  <mobile:Link ID="Link4" href="#form4a" 
      runat="server">Go to Form 4a</mobile:Link>
</mobile:Form>

<mobile:Form ID="Form4a" Runat="server" OnActivate="Form_Activate">
  <mobile:Label ID="Label" runat="server" 
      Text='<%# "Current: " + 
        ((MobilePage)Page).ActiveForm.UniqueID %>' />
  <mobile:Link ID="Link5" href="#form1" 
      runat="server">Go to Form 1</mobile:Link>
  <mobile:Link ID="Link6" href="#form2" 
      runat="server">Go to Form 2</mobile:Link>
  <mobile:Link ID="Link7" href="#form3" 
       runat="server">Go to Form 3</mobile:Link>
  <mobile:Link ID="Link8" href="#form4" 
      runat="server">Go to Form 4</mobile:Link>
</mobile:Form>

See Also

Reference

AddLinkedForms

ResolveFormReference

Other Resources

Developing ASP.NET Mobile Web Pages

Application Developer's Guide