Export (0) Print
Expand All
2 out of 14 rated this helpful - Rate this topic

Creating an ASP.NET Mobile Web Application 

With ASP.NET, the New Project dialog box in Microsoft Visual Studio displays two ASP.NET Mobile Designer project types:

  • Mobile Web Application template under Visual C# Projects

  • Mobile Web Application template under Visual Basic Projects

These application templates provide the basic file references and forms for the specified language. Choosing a template creates and opens the specified project in Visual Studio.

The following walkthrough takes you through the basic steps necessary to create a mobile Web application using the designer.

  1. On the File menu, choose New, and then click Project.

  2. In the New Project dialog box, do the following:

    1. In the Project Types pane, select either Visual Basic Projects or Visual C# Projects.

    2. In the Templates pane, click Mobile Web Application.

    3. In the Name box, enter a name for your project. This is also the name of the project solution.

    4. In the Location box, enter the URL (including http://) of the Web server where you want to create the project.

      NoteNote

      The following software must be installed on the Web server: Internet Information Services (IIS) version 5.0 or later and the Microsoft .NET Framework.

    The designer creates a new mobile Web Forms page called MobileWebForm1. It also creates the following necessary project files:

    • MobileWebForm1.aspx. File format for the ASP.NET Web Forms pages. This file contains the declarative format of the ASP.NET mobile controls.

    • MobileWebForm1.aspx.cs or MobileWebForm1.aspx.vb. Contains the code for handling events and performing other programmatic tasks.

    • AssemblyInfo.cs or AssemblyInfo.vb. Contains a set of attributes that provide information about the assembly built by the project. For more information, see Assemblies Overview.

    • Global.asax and Global.asax.cs or Global.asax.vb. Contain code for responding to application-level events raised by ASP.NET or by HttpModules. These files, also known as the ASP.NET application files, are optional. For more information, see the ASP.NET topic The Global.asax File.

    • web.config. Contains settings specific to the application. For more information, see ASP.NET Configuration.

    The Solution Explorer displays the files and resources in your application. Use this window to view, add, remove, and rename the listed files.

    For more information about creating projects with the designer, see Working with Environment Tools.

  3. The application wizard creates an initial form. Drag controls from the Mobile Web Forms tab of the Toolbox onto the form. Add as many controls as necessary.

    NoteNote

    The Mobile Web Forms tab of the Toolbox is available only when you are in Design view of the designer.

  4. Edit properties in the Properties window.

  5. Repeat steps 3 and 4 until the design for your Web application is complete.

Controls on mobile Web Forms, just like Web Forms controls, can raise various events; for example, a Command control can raise a Click event (this is similar to the Button control in a standard Web Forms control). Controls provide default events and nondefault events. A control's default event is usually the most common event raised for that type of control. For example, the Click event is a Command control's default event. All other events that the control supports are considered nondefault events.

Many events are raised by something the user does in the browser. However, the code to handle the event is executed on the server. When the user clicks a Command control, the page is posted back to the server and then the event information is examined. If your application has an event handler that corresponds to the event, the event handler is called. When the event handler finishes, the application sends the page back to the browser with any changes made by the event handler. For additional information, see Web Server Control Event Model.

All controls provide Init, Load, PreRender, and Unload events. They also support additional events specific to their respective purposes.

To create a default event handler for a control

  1. After placing the control on the form, double-click the control.

    The Web Forms designer opens the code-behind file for the current page and creates skeleton methods for handling the control's default events. For the Command control, the code looks like the following.

    ' Visual Basic
    Private Sub Command1_Click(ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Command1.Click
    End Sub
    
    // C#
       private void Command1_Click(object sender, System.EventArgs e)
       {
       
    
  2. Write code in the control's event handler methods that the application can call when the events occur. For the Command control, your code might resemble the following.

    ' Visual Basic
    Private Sub Command1_Click(ByVal sender as System.Object, ByVal e as System.EventArgs)Handles Command1.Click
       Command1.Text = "Hello, Web Forms!"
    End Sub
    
    // C#
    private void Command1_Click(Object sender, System.EventArgs e)
    {
       Command1.Text = "Hello, Web Forms!";
    
    

To create a nondefault event handler in Visual Basic

  1. Open the code-behind page for the mobile Web Forms page by clicking Code on the View menu in Visual Studio.

  2. From the Class Name drop-down list, select the control to which you want to add the event handler.

  3. From the Method Name drop-down list, choose the event for which you want to add the event handler.

    NoteNote

    The Code Editor automatically inserts the appropriate event-handling method into the code-behind page and positions the insertion point within the method.

  4. Add the appropriate code to the event handler.

To create a nondefault event handler in Visual C#

  1. In Design view, select the control to which you want to add the event handler.

  2. In the Properties window, click the Events button (ASP.NET Mobile Designer Event button). The window shows a list of all the events for the selected control.

  3. Double-click the method name for which you want to create an event handler.

    NoteNote

    The Code Editor opens the code-behind page and inserts the appropriate event-handling method into the code-behind class. It also positions the insertion point within the method.

  4. Add the appropriate code to the event handler.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft. All rights reserved.