MobilePage.ActiveForm Property

Gets or sets the page's currently active form.

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

public Form ActiveForm { get; set; }
/** @property */
public Form get_ActiveForm ()

/** @property */
public void set_ActiveForm (Form value)

public function get ActiveForm () : Form

public function set ActiveForm (value : Form)

Not applicable.

Property Value

The page's currently active form.

Exception typeCondition


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 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" />

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1

Community Additions