MobilePage.ActiveForm Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets or sets the page's currently active form. This API is obsolete. For information about how to develop ASP.NET mobile applications, see the Web site.

Namespace:   System.Web.UI.MobileControls
Assembly:  System.Web.Mobile (in System.Web.Mobile.dll)

public Form ActiveForm { get; set; }

Property Value

Type: System.Web.UI.MobileControls.Form

The page's currently active form.

Exception Condition

The page does not contain any forms.

When a page is initially rendered, the first form in the page is automatically made active. On subsequent postbacks, another form might be made active, either by programmatically setting this property, or as a result of user navigation through a Link control.

The following example demonstrates how to use the ActiveForm property of a Form control. If the current mobile device allows for access keys for controls, the button will display the access key that submits the form.


The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information, see ASP.NET Web Forms Page Code Model.

<%@ Page Language="C#" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Assembly="System.Web.Mobile" %>
<%@ Import Namespace="System.Web.Mobile" %>

<script runat="server">
    private void Command_OnClick(object sender, EventArgs e)
        // Display the other form
        if (ActiveForm.ID == "Form1")
            ActiveForm = Form2;
            ActiveForm = Form1;

    public bool isAccessKey(MobileCapabilities caps, 
        string optValue)
        // Determine if the browser is not a Web crawler 
        // and can use access keys
        if (!caps.Crawler && caps.SupportsAccesskeyAttribute)
            return true;
        return false;

<html xmlns="" >
    <mobile:Form runat="server" id="Form1" >
        <mobile:Label Runat="server">This is Form1</mobile:Label>
        <mobile:Command id="cmd1" runat="server" Text="No AccessKey" 
               <Choice Filter="isAccessKey" Text="AccessKey is 1"/>
        <mobile:Label id="Label1" runat="server" />
    <mobile:Form ID="Form2" Runat="server">
        <mobile:Label Runat="server">This is Form2</mobile:Label>
        <mobile:Command id="cmd2" runat="server" text="Back to Form1"
                <Choice Filter="isAccessKey" Text="1 is AccessKey" AccessKey="1" />

.NET Framework
Available since 1.1
Return to top