PRB: You Cannot Navigate to a Specific Form By Using the #FormName Syntax (312572)



The information in this article applies to:

  • Microsoft Mobile Internet Toolkit (MMIT)

This article was previously published under Q312572

SYMPTOMS

When you set the NavigateURL property of the mobile link control to a page to which to navigate and to a form to display (such as: page2.aspx#myForm), the page navigates to the second page, but it does not navigate to the form that you have specified.

CAUSE

This behavior occurs because the Microsoft Mobile Internet Toolkit runtime does not parse the URL for a form name.

RESOLUTION

To resolve this behavior, use a QueryString variable, and then use server-side code to perform the navigation:

Create a Mobile Web Form with a Link Control

The following code contains a mobile Link control that is used to navigate to the Page2.aspx page. Notice that the NavigateURL property of the control specifies the page to which to navigate. This property also contains the FormNavigateQueryString variable that you set equal to FormNavigate.

Add the following code sample to an empty .aspx page on your Web server, and then name it Page1.aspx:
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
<%@ Page Language="vb" Inherits="System.Web.UI.MobileControls.MobilePage" %>
  <mobile:Form id="Form1" runat="server">
    <mobile:Link id="Link1" runat="server" NavigateURL="Page2.aspx?FormNavigate=Form2">
    Go To Form2
    </mobile:Link>
  </mobile:Form>
				

Create a Mobile Web Form

Create a mobile Web Form to which to navigate.

The following code contains two mobile Web Forms to which a user can navigate. The first form is rendered if a QueryString is not provided when this page is requested. The second form is rendered if a QueryString that is called FormNavigate has a value of Form2.

Add the following code sample to an empty .aspx page, and then name it Page2.aspx:
<%@ Page Language="vb" Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
  <mobile:Form id="Form1" runat="server">
    <mobile:Label id="Label1" runat="server">
    Form 1
    </mobile:Label>
  </mobile:Form>

  <mobile:Form id="Form2" runat="server">
    <mobile:Label id="Label2" runat="server">
    Form 2
    </mobile:Label>
  </mobile:Form>
				

Process the QueryString with Microsoft Visual Basic .NET

The following code uses the Page_Load event to process the QueryString variable:

To do this, the QueryString variable called FormNavigate is retrieved and then stored in a local variable called navigateToForm. If navigateToForm is not empty, the Page.FindControl using navigateToForm as the argument is called. A reference to the correct form is received, it is stored in a variable called myForm, and then the ActiveForm property is set equal to myForm.

Add the following code sample to the Page2.aspx page after the code that you added in the "Create a Mobile Web Form" section:
<Script runat="server">
  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
    If Not Page.IsPostBack Then    
      ' Retrieve the QueryString Value  
      Dim navigateToForm As String
      navigateToForm = Request.QueryString("FormNavigate")

      ' Run navigation code if navigateToForm is not empty       
      If navigateToForm <> "" Then
        Dim myForm As Form

        ' Find and navigate to the form
        myForm = Page.FindControl(navigateToForm)
        ActiveForm = myForm
      End If
    End If
  End Sub
</Script>
				

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Behavior

Modify the solution code in Page1.aspx:

Change the following line
<mobile:Link id="Link1" runat="server" NavigateURL="Page2.aspx?FormNavigate=Form2">
to:
<mobile:Link id="Link1" runat="server" NavigateURL="Page2.aspx#Form2">
If you browse to the initial page and click the link, you see that Form1 is displayed rather than Form2.

Modification Type:MajorLast Reviewed:6/14/2002
Keywords:kbDSupport kbNavigation kbprb kbServerControls KB312572 kbAudDeveloper