Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

How to make server controls browser compatible

0.00/5 (No votes)
3 Jun 2011 1  
IntroductionIn modern web development, we need to check the browser compatibility for our web pages. This can include changing the css classes,

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

Introduction

In modern web development, we need to check the browser compatibility for our web pages. This can include changing the css classes, style to fix the design issues. Using ASP.NET we can check the browser compatibility without writing a single line of code for the server controls.

Let's check out some code samples:

If we will define css classes like:
.IEStyle{color:Red;}
.FFStyle{color:Blue;}
.DefaultStyle{color:Black;}

Create a Label control in your page.
Label control:

<asp:Label ID="lblTest" runat="server" ie:CssClass="IEStyle"  
mozilla:CssClass="FFStyle" CssClass="DefaultStyle" ie:Text="You are in Internet  
explorer." mozilla:Text="You are in Firefox." Text="You are in other browser."  
/>

Just make page run in the different browser and see the changes as below:

Output:
IE  : You are in Internet explorer.
FF : You are in Firefox.
Others : You are in other browser.
 

You can try the same with the TextBox control.
TextBox Control:

<asp:TextBox ID="TestTextBox" runat="server" ie:Text="You are in Internet explorer."  
mozilla:Text="You are in Firefox." Text="You are in other browser." ie:CssClass="IEStyle"  
mozilla:CssClass="FFStyle" 
CssClass="DefaultStyle" />

 

 We can use these setting for all server controls.

And for loading different css files for different browsers you can use the following:

<link runat="server" href="~/Styles/Site.css" mozilla:href="~/MOZStyleSheet.css" ie:href="~/IEStyleSheet.css" rel="stylesheet" type="text/css" />

NOTE : There is no intellisense available for above in Visual Studio

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here