共用方式為


How to: Add ASP.NET Web Forms Page to a Web Project

This topic describes how to add new and existing Web Forms pages to a Web project. For information about creating an ASP.NET Web project, see How to: Create File System Web Site Projects or How to: Create New Web Application Projects.

Note

This topic applies only to ASP.NET Web Forms pages. It does not apply to pages that you create using ASP.NET MVC (Model View Controller) or ASP.NET Web Pages.

Web site projects in Visual Studio are directory based. When you open a Web site project, Visual Studio treats all of the files in the folder you open — whether the files are in the file system, in an Internet Information Services (IIS) application, or on an FTP site — as part of the same Web site. For Web application projects, the project file (.csproj or .vbproj) determines whether a file is included in the project or not. The procedures in this topic will work for both project types.

For information about the difference between Web site projects and Web application projects, see Web Application Projects versus Web Site Projects in Visual Studio.

To add a new ASP.NET Web Forms page to a Web site

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

  2. In the Add New Item dialog box, under Installed Templates, click the language that you want to work with, and then click Web Form.

    Note

    You can include pages with different programming languages in the same Web site project. For more information, see Walkthrough: Code Editing in Web Forms Pages in Visual Studio.

  3. If you want the code for the page to be in a separate file, be sure that the Place code in separate file check box is selected. If you want to keep the code and markup in the same file, clear this check box.

  4. In the Name box, type a name for the new Web page, and then click Add.

    The new ASP.NET Web page is created and displayed in Visual Studio.

To add an existing ASP.NET Web Forms page to a Web site project

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

  2. In the Add Existing Item dialog box, navigate to the directory containing the Web page that you want to add, select the page, and then click Open.

    The ASP.NET Web page is added to the project.

    Note

    When you add an existing file to a Web site, the file is copied to your project, not added by reference. Thus, if you change the file in your project, the original file is left unchanged.

Changing the Name of ASP.NET Web Forms Page

After creating a new ASP.NET Web Forms page or adding an existing page to a Web site project, you might want to change the name of the page file. You can easily rename pages in Solution Explorer.

To change the name of an ASP.NET Web Forms page using Solution Explorer

  1. In Solution Explorer, right-click the file that you want to change and then click Rename.

  2. Type the new file name that you want and then press ENTER.

    Note

    If the code for the page is in a separate file, Visual Studio renames the code file as well and changes the @ Page directive in the .aspx page to match the renamed code file.

See Also

Other Resources

ASP.NET Web Projects