Microsoft KB Archive/320985

= How to add a CSS style sheet reference to all Web forms in a Visual C# .NET Web project =

Article ID: 320985

Article Last Modified on 10/17/2005

-

APPLIES TO


 * Microsoft ASP.NET 1.0
 * Microsoft Visual C# .NET 2002 Standard Edition
 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * Microsoft Visual Studio .NET 2002 Academic Edition
 * Microsoft ASP.NET 1.1
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual Studio .NET 2003 Professional Edition
 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Studio .NET 2003 Academic Edition

-



This article was previously published under Q320985





For a Microsoft Visual Basic .NET version of this article, see 323843.

IN THIS TASK
SUMMARY
 * Edit WebProjectItems.vsdir file
 * Create custom Web form wizard
 * Create custom Web form template
 * Test Link reference

REFERENCES



SUMMARY
This step-by-step article describes how to create a custom Web Form template so that you can include a cascading style sheet (CSS) reference in all Web Forms in a Visual C# .NET Web project.

Typically, Web site designers must maintain a consistent look-and-feel on every page for a particular Web site. This article describes how to create a custom Web Form template that contains a link to a CSS style sheet. When you create all Web Forms in an application with this template, you provide an easy way to maintain a consistent design across the site.

The technique that is described in this article is based on the concept of Microsoft Visual Studio .NET Enterprise Templates. For more information, see the &quot;REFERENCES&quot; section of this article.

back to the top

Edit WebProjectItems.vsdir file
 In Notepad, open the WebProjectItems.vsdir file from the following folder:

In Visual Studio .NET 2002:

C:\Program Files\Microsoft Visual Studio .NET\VC#\CSharpProjectItems\WebProjectItems

In Visual Studio .NET 2003:

C:\Program Files\Microsoft Visual Studio .NET 2003\VC#\CSharpProjectItems\WebProjectItems

  Add the following text to the end of the file: ..\MyCustomWebFormWiz.vsz|{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}|My Custom Form|10|#2263|{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}|4534|0|WebForm.aspx  Save the file.

back to the top

Create custom Web form wizard
 Open the following folder:

In Visual Studio .NET 2002:

C:\Program Files\Microsoft Visual Studio .NET\VC#\CSharpProjectItems

In Visual Studio .NET 2003:

C:\Program Files\Microsoft Visual Studio .NET 2003\VC#\CSharpProjectItems

 Copy the CSharpAddWebFormWiz.vsz file to the MyCustomWebFormWiz.vsz file.</li>  In Notepad, open the MyCustomWebFormWiz.vsz file, and then change the Param value as follows: Param=&quot;WIZARD_NAME = MyCustomWebFormWiz&quot; </li> Save the file.</li></ol>

back to the top

Create custom Web form template
 Open the following folder:

In Visual Studio .NET 2002:

C:\Program Files\Microsoft Visual Studio .NET\VC#\VC#Wizards

In Visual Studio .NET 2003:

C:\Program Files\Microsoft Visual Studio .NET 2003\VC#\VC#Wizards

</li> Copy CSharpAddWebFormWiz to a new directory that is named MyCustomWebFormWiz.</li> Open the following folder:

In Visual Studio .NET 2002:

C:\Program Files\Microsoft Visual Studio .NET\VC#\VC#Wizards\MyCustomWebFormWiz\Templates\1033

In Visual Studio .NET 2003:

C:\Program Files\Microsoft Visual Studio .NET 2003\VC#\VC#Wizards\MyCustomWebFormWiz\Templates\1033

</li>  In Notepad, open the WebForm1.aspx file, and then add the following link reference (which appears indented) between the <meta name=vs_targetSchema> tag and the closing tag as follows: <meta name=vs_targetSchema content=&quot;[!output DEFAULT_TARGET_SCHEMA]&quot;> <link id=&quot;link1&quot; rel=&quot;stylesheet&quot; href=&quot;myStyleSheet.css&quot; type=&quot;text/css&quot; runat=&quot;server&quot; /> </li> Save the file.</li></ol>

back to the top

Test link reference

 * 1) Start Microsoft Visual Studio .NET.
 * 2) On the File menu, point to New, and then click Project.
 * 3) Click Visual C# Projects under Project Types, and then click ASP.NET Web Application under Templates.
 * 4) On the Project menu, click Add New Item to add a style sheet to the project, and then name the style sheet myStyleSheet.css.
 * 5) Set the background color of the body element to blue for testing purposes.
 * 6) On the Project menu, click Add New Item.
 * 7) Click My Custom Form under Templates, name the file, and then click Open to add a custom Web Form to the application. Notice that the style sheet is applied automatically to the new Web Form and that the background is blue.

back to the top

<div class="references_section">