Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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.
On the File menu, choose New, and then click Project.
In the New Project dialog box, do the following:
In the Project Types pane, select either Visual Basic Projects or Visual C# Projects.
In the Templates pane, click Mobile Web Application.
In the Name box, enter a name for your project. This is also the name of the project solution.
In the Location box, enter the URL (including https://) of the Web server where you want to create the project.
Note
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.
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.
Note
The Mobile Web Forms tab of the Toolbox is available only when you are in Design view of the designer.
Edit properties in the Properties window.
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.
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) {
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!";
Open the code-behind page for the mobile Web Forms page by clicking Code on the View menu in Visual Studio.
From the Class Name drop-down list, select the control to which you want to add the event handler.
From the Method Name drop-down list, choose the event for which you want to add the event handler.
Note
The Code Editor automatically inserts the appropriate event-handling method into the code-behind page and positions the insertion point within the method.
Add the appropriate code to the event handler.
In Design view, select the control to which you want to add the event handler.
In the Properties window, click the Events button (
). The window shows a list of all the events for the selected control.
Double-click the method name for which you want to create an event handler.
Note
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.
Add the appropriate code to the event handler.
How to: Create Event Handlers in ASP.NET Web Pages (Visual Studio)
Compiling and Running an Application
Debugging an Application
Organizing Content with Containers