CSS Improvements in Visual Studio 2010

One of the major areas of work in ASP.NET 4 Beta 2 has been around rendering HTML that is compliant with the latest HTML standards. This includes changes to how ASP.NET Web server controls use CSS styles.

Compatibility Setting for Rendering

By default, when a Web application or Web site targets the .NET Framework 4, the controlRenderingCompatibilityVersion attribute of the pages element is set to “4.0”. This element is defined in the machine-level Web.config file and by default applies to all ASP.NET 4 applications:

<system.web>

<pages controlRenderingCompatibilityVersion="3.5|4.0"/>

</system.web>

The value for controlRenderingCompatibility is a string, which allows potential new version definitions in future releases. In the current release, the following values are supported for this property:

· “3.5”. This setting indicates legacy rendering and markup. Markup rendered by controls is 100% backward compatible, and the setting of the xhtmlConformance property is honored.

· “4.0”. If the property has this setting, ASP.NET Web server controls do the following:

· The xhtmlConformance property is always treated as “Strict”. As a result, controls render XHTML 1.0 Strict markup.

· Disabling non-input controls no longer renders invalid styles.

· div elements around hidden fields are now styled so they do not interfere with user-created CSS rules.

· Menu controls render markup that is semantically correct and compliant with accessibility guidelines.

· Validation controls do not render inline styles.

· Controls that previously rendered border="0" (controls that derive from the ASP.NET Table control, and the ASP.NET Image control) no longer render this attribute.

Disabling Controls

In ASP.NET 3.5 SP1 and earlier versions, the framework renders the disabled attribute in the HTML markup for any control whose Enabled property set to false. However, according to the HTML 4.01 specification, only input elements should have this attribute.

In ASP.NET  4, you can set the controlRenderingCompatabilityVersion property to “3.5”, as in the following example:

<system.web>

<pages controlRenderingCompatibilityVersion="3.5"/>

</system.web>

You might create markup for a Label control like the following, which disables the control:

<asp:Label id="Label" runat="server" Text="Test" Enabled="false">

The Label control would render the following HTML:

<span id="Label1" disabled="disabled">Test</span>

In ASP.NET 4 Beta 2, you can set the controlRenderingCompatabilityVersion to “4.0”. In that case, only controls that render input elements will render a disabled attribute when the control’s Enabled property is set to false. Controls that do not render HTML input elements instead render a class attribute that references a CSS class that you can use to define a disabled look for the control. For example, the Label control shown in the earlier example would generate the following markup:

<span id="Label1" class="aspNetDisabled">Test</span>

The default value for the class that specified for this control is “aspNetDisabled”. However, you can change this default value by setting the static DisabledCssClass static property of the WebControl class. For control developers, the behavior to use for a specific control can also be defined using the SupportsDisabledAttribute property.

Posted in: software General | Tags: rendering vsts vs 2010 visual studio css improvement compatibility disabling xhtml

Project Template Changes in Visual Studio 2010

In earlier versions of ASP.NET, when you use Visual Studio to create a new Web Site project or Web Application project, the resulting projects contain only a Default.aspx page, a default Web.config file, and the App_Data folder, as shown in the following figure:

Visual Studio also supports an Empty Web Site project type, which contains no files at all, as shown in the following figure:

The result is that for the beginner, there is very little guidance on how to build a production Web application. Therefore, ASP.NET 4 Beta 2 introduces three new templates, one for an empty Web application project, and one each for a Web Application and Web Site project.

Empty Web Application Template

As the name suggests, the Empty Web Application template is a stripped-down Web Application project. You select this project template from the Visual Studio New Project dialog box, as shown in the following figure:

When you create an Empty ASP.NET Web Application, Visual Studio creates the following folder layout:

This is similar to the Empty Web Site layout from earlier versions of ASP.NET, with one exception. In Visual Studio 2010 Beta 2, Empty Web Application and Empty Web Site projects contain the following minimal Web.config file that contains information used by Visual Studio to identify the framework that the project is targeting:

Without this targetFramework property, Visual Studio defaults to targeting the .NET Framework 2.0 in order to preserve compatibility when opening older applications.

Web Application and Web Site Project Templates

The other two new project templates that are shipped with Visual Studio 2010 Beta 2 contain major changes. The following figure shows the project layout that is created when you create a new Web Application project. (The layout for a Web Site project is virtually identical.)

The project includes a number of files that were not created in earlier versions. In addition, the new Web Application project is configured with basic membership functionality, which lets you quickly get started in securing access to the new application. Because of this inclusion, the Web.config file for the new project includes entries that are used to configure membership, roles, and profiles. The following example shows the Web.config file for a new Web Application project. (In this case, roleManager is disabled.)

The project also contains a second Web.config file in the Account directory. The second configuration file provides a way to secure access to the ChangePassword.aspx page for non-logged in users. The following example shows the contents of the second Web.config file.

The pages created by default in the new project templates also contain more content than in previous versions. The project contains a default master page and CSS file, and the default page (Default.aspx) is configured to use the master page by default. The result is that when you run the Web application or Web site for the first time, the default (home) page is already functional. In fact, it is similar to the default page you see when you start up a new MVC application.

The intention of these changes to the project templates is to provide guidance on how to start building a new Web application. With semantically correct, strict XHTML 1.0-compliant markup and with layout that is specified using CSS, the pages in the templates represent best practices for building ASP.NET 4 Web applications. The default pages also have a two-column layout that you can easily customize.

For example, imagine that for a new Web Application you want to change some of the colors and insert your company logo in place of the My ASP.NET Application logo. To do this, you create a new directory under Content to store your logo image:

To add the image to the page, you then open the Site.Master file, find where the My ASP.NET Application text is defined, and replace it with an image element whose src attribute is set to the new logo image, as in the following example:

You can then go into the Site.css file and modify CSS class definitions to change the background color of the page as well as that of the header, as in the following example:

The result of these changes is that you can display a customized home page with very little effort:

Posted in: General | Tags: web application vsts vs 2010 web site project templates web application template web site template rolemanager

Unable to read project file. Configured to use IIS

Converted a remote solution (resides on development server on intranet) from VS2003 to VS2005. Attempted to open solution from local client using VS2005 SP1 running on Vista. When I attempt to open the solution using VS2005, I get "Unable to read the project file 'proj1.vbproj.' The Web Application Project proj1 is configured to use IIS. Could not find the server 'http://remoteservername' on the local machine.

Belong to administrators group on local client. Ran VS2005 as administrator.

Went into Turn Windows features on and off in control panel on local Vista client and checked all IIS 6 compatability checkboxes as outlined in http://blogs.msdn.com/shahpiyush/archive/2007/06/01/3028325.aspx also, verified that ASP.net box is checked.

The solution is edit the .csproj with notepad and change this line :

<WebProjectProperties>
          <UseIIS>True</UseIIS>

To :

<WebProjectProperties>
          <UseIIS>False</UseIIS>

Posted in: programming problems and solutions | Tags: vsts iis project file webprojectproperties useiis compatability