How to Make Server Controls Browser Compatible Using ASP.NET

How to Make Server Controls Browser Compatible Using ASP.NET

Introduction

In modern web development, we need to check the browser compatibility for our web pages. This can include changing the css styles for 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.

For adding different css files for different browsers 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

Leave a Comment
  • Please add 5 and 3 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Ed Price - MSFT edited Revision 5. Comment: Title guidelines - added technology to title

Page 1 of 1 (1 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Ed Price - MSFT edited Revision 5. Comment: Title guidelines - added technology to title

Page 1 of 1 (1 items)