Share via


Linking Between Mobile Web Forms

If you have a link of the format #form1 in a control contained in a user control, the ResolveFormReference method looks for a form with the value of the id property set to form1 in the user control. If the form is not found, it first 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).

The following .aspx Active Server Page and the .ascx user control code example demonstrate navigation between forms.

Example Formtest.aspx

<%@ Page Language="C#" Inherits="System.Web.UI.MobileControls.MobilePage" Debug="true" %>
<%@ 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>
<mobile:Form runat="server" id="form1" OnActivate="Form_Activate">
    <mobile:Label runat="server" Text="<%# ActiveForm.UniqueID %>" />
    <mobile:Link NavigateURL="#form2" runat="server">Go to Form 2</mobile:Link>
    <mobile:Link NavigateURL="#form3" runat="server">Go to Form 3</mobile:Link>
    <mobile:Link NavigateURL="#mc1:form4" runat="server">Go to Form 4</mobile:Link>
</mobile:Form>

<mobile:Form runat="server" id="form2" OnActivate="Form_Activate">
    <mobile:Label runat="server" Text="<%# ActiveForm.UniqueID %>" />
    <mobile:Link NavigateURL="#form1" runat="server">Go to Form 1</mobile:Link>
    <mobile:Link NavigateURL="#form3" runat="server">Go to Form 3</mobile:Link>
    <mobile:Link NavigateURL="#mc1:form4" runat="server">Go to Form 4</mobile:Link>
</mobile:Form>

<mobile:Form runat="server" id="form3" OnActivate="Form_Activate">
    <mobile:Label runat="server" Text="<%# ActiveForm.UniqueID %>" />
    <mobile:Link NavigateURL="#form1" runat="server">Go to Form 1</mobile:Link>
    <mobile:Link NavigateURL="#form2" runat="server">Go to Form 2</mobile:Link>
    <mobile:Link NavigateURL="#mc1:form4" runat="server">Go to Form 4</mobile:Link>
</mobile:Form>

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

Example Formtest.ascx

<%@ Control Language="c#" Inherits="System.Web.UI.MobileControls.MobileUserControl" %>

<script runat="server">
    void Form_Activate(Object sender, EventArgs e)
    {
        ((Form)sender).DataBind();
    }
</script>
<mobile:Form runat="server" id="form4" OnActivate="Form_Activate">
    <mobile:Label runat="server" Text="<%# 
        ((MobilePage)Page).ActiveForm.UniqueID %>" />
    <mobile:Link NavigateURL="#form1" runat="server">
        Go to Form 1</mobile:Link>
    <mobile:Link NavigateURL="#form2" runat="server">
        Go to Form 2</mobile:Link>
    <mobile:Link NavigateURL="#form3" runat="server">
        Go to Form 3</mobile:Link>
    <mobile:Link NavigateURL="#form4a" runat="server">
        Go to Form 4a</mobile:Link>
</mobile:Form>

<mobile:Form runat="server" id="form4a" OnActivate="Form_Activate">
    <mobile:Label runat="server" Text="<%# ((MobilePage)Page).ActiveForm.UniqueID %>" />
    <mobile:Link NavigateURL="#form1" runat="server">
        Go to Form 1</mobile:Link>
    <mobile:Link NavigateURL="#form2" runat="server">
        Go to Form 2</mobile:Link>
    <mobile:Link NavigateURL="#form3" runat="server">
        Go to Form 3</mobile:Link>
    <mobile:Link NavigateURL="#form4" runat="server">
        Go to Form 4</mobile:Link>
</mobile:Form>

See Also

Developing ASP.NET Mobile Web Applications | AddLinkedForms Method | ResolveFormReference Method | Application Developer's Guide