
Creating a Web Site and Page
In this part of the walkthrough, you will create a Web site and add a new page to it. You will also add HTML text and run the page in your Web browser.
For this walkthrough, you will create a file system Web site that does not require that you work with Microsoft Internet Information Services (IIS). Instead, you will create and run your page in the local file system.
A file system Web site is one that stores pages and other files in a folder that you choose somewhere on your local computer. Other Web site options include a local IIS Web site, which stores your files in a subfolder of the local IIS root (typically, \Inetpub\Wwwroot\). An FTP site stores files on a remote server that you gain access to across the Internet by using File Transfer Protocol (FTP). A remote site stores files on a remote server that you can access across a local network. For more information, see Walkthrough: Editing Web Sites with FTP in Visual Web Developer. Also, Web site files can be stored in a source control system such as Visual SourceSafe. For more information, see Introducing Source Control.
To create a file system Web site
Open Visual Web Developer.
On the File menu, click New Web Site.
The New Web Site dialog box appears, as shown in the following screen shot.
New Web Site dialog box
.png)
Under Visual Studio installed templates, click ASP.NET Web Site.
When you create a Web site, you specify a template. Each template creates a Web application that contains different files and folders. In this walkthrough, you are creating a Web site based on the ASP.NET Web Site template, which creates some folders and a few default files.
In the Location box, select the File System box, and then enter the name of the folder where you want to keep the pages of your Web site.
For example, type the folder name C:\BasicWebSite.
In the Language list, select Visual Basic or Visual C#.
The programming language you choose will be the default for your Web site. However, you can use multiple languages in the same Web application by creating pages and components in different programming languages.
Click OK.
Visual Web Developer creates the folder and a new page named Default.aspx. When a new page is created, by default Visual Web Developer displays the page in Source view, where you can see the page's HTML elements. The following screen shot shows the Source view of a default Web page.
Source view of default page
.gif)
A Tour of Visual Web Developer
Before you proceed with working on the page, it is useful to familiarize yourself with the Visual Web Developer development environment. The following illustration shows you the windows and tools that are available in Visual Web Developer.
Note: |
|---|
This diagram shows default windows and window locations. The View menu allows you to display additional windows, and to rearrange and resize windows to suit your preferences. If changes have already been made to the window arrangement, what you see will not match the diagram. |
Diagram of Visual Web Developer environment
.gif)
To familiarize yourself with the Web designer in Visual Web Developer
Examine the preceding illustration and match the text to the following list, which describes the most commonly used windows and tools. (Not all windows and tools that you see are listed here, only those marked in the preceding illustration.)
Toolbars. Provide commands for formatting text, finding text, and so on. Some toolbars are available only when you are working in Design view.
Solution Explorer. Displays the files and folders in your Web site.
Document window. Displays the documents you are working on in tabbed windows. You can switch between documents by clicking tabs.
Properties window. Allows you to change settings for the page, HTML elements, controls, and other objects.
View tabs. Present you with different views of the same document. Design view is a near-WYSIWYG editing surface. Source view is the HTML editor for the page. Split view displays both the Design view and the Source view for the document. You will work with the Design and Source views later in this walkthrough. If you prefer to open Web pages in Design view, on the Tools menu, click Options, select the HTML Designer node, and change the Start Pages In option.
Toolbox. Provides controls and HTML elements that you can drag onto your page. Toolbox elements are grouped by common function.
Server Explorer/Database Explorer. Displays database connections. If Server Explorer is not visible in Visual Web Developer, on the View menu, click Server Explorer or Database Explorer.
Creating a New Web Forms Page
When you create a new Web site, Visual Web Developer adds an ASP.NET page (Web Forms page) named Default.aspx. You can use the Default.aspx page as the home page for your Web site. However, for this walkthrough, you will create and work with a new page.
To add a page to the Web site
Close the Default.aspx page. To do this, right-click the tab containing the file name and select Close.
In Solution Explorer, right-click the Web site (for example, C:\BasicWebSite), and then click Add New Item.
Under Visual Studio installed templates, click Web Form. The following screen shot shows the Add New Item dialog box.
Add New Item dialog box
.png)
In the Name box, type FirstWebPage.
In the Language list, choose the programming language you prefer to use (Visual Basic, C#, or J#). When you created the Web site, you specified a default language. However, each time you create a new page or component for your Web site, you can change the language from the default. You can use different programming languages in the same Web site.
Clear the Place code in separate file check box.
In this walkthrough, you are creating a single-file page with the code and HTML in the same page. The code for ASP.NET pages can be located either in the page or in a separate class file. To learn more about keeping the code in a separate file, see Walkthrough: Creating a Basic Web Page with Code Separation in Visual Web Developer.
Click Add.
Visual Web Developer creates the new page and opens it.
Adding HTML to the Page
In this part of the walkthrough, you will add some static text to the page.
To add text to the page
At the bottom of the document window, click the Design tab to switch to Design view.
Design view displays the page that you are working on in a WYSIWYG-like way. At this point, you do not have any text or controls on the page, so the page is blank except for a dashed line that outlines a rectangle. This rectangle represents a div element on the page.
Click inside the rectangle that is outlined by a dashed line.
Type Welcome to Visual Web Developer and press Enter twice.
The following screen shot shows the text you typed in Design view.
Welcome text as seen in Design view
.gif)
Switch to Source view.
You can see the HTML that you created by typing in Design view, as shown in the following screen shot.
Welcome text as seen in Source view
.gif)
Running the Page
Before you proceed with adding controls to the page, you can try running it. To run a page, you need a Web server. In a production Web site, you use IIS as your Web server. However, to test a page, you can use the ASP.NET Development Server, which runs locally and does not require IIS. For file system Web sites, the default Web server in Visual Web Developer is the ASP.NET Development Server.
To run the page
In Solution Explorer, right-click FirstPage.aspx and select Set as Start Page.
Press CTRL+F5 to run the page.
Visual Web Developer starts the ASP.NET Development Server. An icon appears on the toolbar to indicate that the Visual Web Developer Web server is running, as shown in the following screen shot.
Visual Web Developer Web server icon
.gif)
The page is displayed in the browser. Although the page you created has an extension of .aspx, it currently runs like any HTML page.
To display a page in the browser you can also right-click the page in Solution Explorer and select View in Browser.
Close the browser.