Creating an ASP.NET Mobile User Control

One type of programmer-defined control provided by the ASP.NET mobile controls is the mobile user control. Mobile user controls inherit from the base class MobileUserControl in the namespace System.Web.UI.MobileControls. These controls are stored in files with an .ascx extension.

Mobile user controls provide powerful techniques for extending the functionality of the ASP.NET mobile controls. For example, you can place nearly any control into a mobile user control. This includes both ASP.NET mobile controls and custom controls. You can even put a StyleSheet control into a mobile user control as a way of sharing styles among ASP.NET mobile Web pages. However, note that a DeviceSpecific control cannot be placed at the root level of a user control.

When defining a mobile user control, you can create it in Visual Studio and optionally store its code in a code-behind page. For more information, see Converting a Web Forms Page to a User Control and What's New in Code-Behind Support in Visual Web Developer.

ASP.NET mobile controls enable you to develop mobile user controls in any .NET language such as Visual Basic or Visual C#. Use the following procedure to create mobile user controls in Visual Studio. The following procedure assumes that you have a Web application currently running in Visual Studio (Visual Web Developer). If you do not, begin by creating a new ASP.NET Web site in Visual Studio.

To create a mobile user control

  1. In Solution Explorer, right-click the project name and then click Add New Item.

  2. Under Visual Studio installed templates, select Mobile Web User Control, provide a name and select a language, and then click OK.

    The designer displays a blank page.

  3. Drag controls from the Toolbox and configure their properties as appropriate.

  4. Add method and event handlers to the code-behind page, as needed.

See Also

Concepts

Introduction to Programmer-Defined Controls

Other Resources

Creating New Controls for ASP.NET Mobile Pages