Microsoft KB Archive/312572

= PRB: You Cannot Navigate to a Specific Form By Using the #FormName Syntax =

Article ID: 312572

Article Last Modified on 6/14/2002

-

APPLIES TO


 * Microsoft Mobile Internet Toolkit 1.0

-



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=&quot;mobile&quot; Namespace=&quot;System.Web.UI.MobileControls&quot; Assembly=&quot;System.Web.Mobile&quot; %> <%@ Page Language=&quot;vb&quot; Inherits=&quot;System.Web.UI.MobileControls.MobilePage&quot; %>   Go To Form2  

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=&quot;vb&quot; Inherits=&quot;System.Web.UI.MobileControls.MobilePage&quot; %> <%@ Register TagPrefix=&quot;mobile&quot; Namespace=&quot;System.Web.UI.MobileControls&quot; Assembly=&quot;System.Web.Mobile&quot; %>   Form 1  

  Form 2  

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 &quot;Create a Mobile Web Form&quot; section: <Script runat=&quot;server&quot;> 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(&quot;FormNavigate&quot;)

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

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

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

Steps to Reproduce the Behavior
Modify the solution code in Page1.aspx:

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

Keywords: kbnavigation kbprb kbservercontrols KB312572

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.