This tutorial will show how to reference the Browser object to retrieve information about what your client can display. C# version.
In this tutorial, we reference the Browser Object to display information about both the Client and the Browser. This could help us determine how our users see our page, depending upon their settings. These could also help us display our page differently so that our users get the most out of the site, no matter what their set-up.
We used over 10 web hosting companies before we found Server Intellect. Their dedicated servers and add-ons were setup swiftly, in less than 24 hours. We were able to confirm our order over the phone. They respond to our inquiries within an hour. Server Intellect's customer support and assistance are the best we've ever experienced.
The text attribute of each label in the ASPX page will be dynamically changed upon runtime, depending upon the user configuration / browser.First, let's create a layout to display the information:
| <form id="form1" runat="server"> <div> Browser Capabilities:<br /> </form> <table style="width: 95%; position: static; text-align: left"> <tr> </table><td style="vertical-align: top; width: 30%; text-align: right"> ActiveX Controls:</td> <td style="vertical-align: top; width: 70%; text-align: left"> </tr><asp:Label ID="Label1" runat="server"></asp:Label></td> <tr> <td style="vertical-align: top; width: 30%; text-align: right"> AOL:</td> <td style="vertical-align: top; width: 70%; text-align: left"> </tr><asp:Label ID="Label2" runat="server"></asp:Label></td> <tr> <td style="vertical-align: top; width: 30%; text-align: right"> Background Sounds:</td> <td style="vertical-align: top; width: 70%; text-align: left"> </tr><asp:Label ID="Label3" runat="server"></asp:Label></td> <tr> <td style="vertical-align: top; width: 30%; text-align: right"> CDF:</td> <td style="vertical-align: top; width: 70%; text-align: left"> </tr><asp:Label ID="Label4" runat="server"></asp:Label></td> <tr> <td style="vertical-align: top; width: 30%; text-align: right"> .NET Framework:</td> <td style="vertical-align: top; width: 70%; text-align: left"> </tr><asp:Label ID="Label5" runat="server"></asp:Label></td> <tr> <td style="vertical-align: top; width: 30%; text-align: right"> Cookies:</td> <td style="vertical-align: top; width: 70%; text-align: left"> </tr><asp:Label ID="Label6" runat="server"></asp:Label></td> <tr> <td style="vertical-align: top; width: 30%; text-align: right"> ECMA:</td> <td style="vertical-align: top; width: 70%; text-align: left"> </tr><asp:Label ID="Label7" runat="server"></asp:Label></td> <tr> <td style="vertical-align: top; width: 30%; text-align: right"> HTML Frames:</td> <td style="vertical-align: top; width: 70%; text-align: left"> </tr><asp:Label ID="Label8" runat="server"></asp:Label></td> <tr> <td style="vertical-align: top; width: 30%; text-align: right"> Java Applets:</td> <td style="vertical-align: top; width: 70%; text-align: left"> </tr><asp:Label ID="Label9" runat="server"></asp:Label></td> <tr> <td style="vertical-align: top; width: 30%; text-align: right"> Browser Version:</td> <td style="vertical-align: top; width: 70%; text-align: left"> </tr><asp:Label ID="Label10" runat="server"></asp:Label></td> <tr> <td style="vertical-align: top; width: 30%; text-align: right"> Broswer Platform:</td> <td style="vertical-align: top; width: 70%; text-align: left"> </tr><asp:Label ID="Label11" runat="server"></asp:Label></td> <tr> <td style="vertical-align: top; width: 30%; text-align: right"> </tr></td> <td style="vertical-align: top; width: 70%; text-align: left"> </td> <br /> </div> |
Try Server Intellect for Windows Server Hosting. Quality and Quantity!
The following code checks for values for specific properties of the Browser Object.We are able to output these values to the user to notify them, but we are also able to use these values in the code to display our page differently to different users. For example, not using ActiveX Controls if the user's browser does not support ActiveX.
The code-behind should look something like this:
| using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) } { if (Request.Browser.ActiveXControls == true) }{ Label1.Text = "This browser supports ActiveX Controls."; }else { Label1.Text = "This browser does not support ActiveX controls."; }if (Request.Browser.AOL == true) { Label2.Text = "This browser is AOL."; }else { Label2.Text = "This browser is not AOL."; }if (Request.Browser.BackgroundSounds == true) { Label3.Text = "This browser supports Background Sounds."; }else { Label3.Text = "This browser does not support Background Sounds."; }if (Request.Browser.CDF == true) { Label4.Text = "This browser supports Channel Definition Format."; }else { Label4.Text = "This browser does not support Channel Definition Format."; }if (Request.Browser.ClrVersion.ToString() != "0.0") { Label5.Text = "This client supports the .NET Framework! You are running version " + Request.Browser.ClrVersion.ToString(); }else { Label5.Text = "You do not have the .NET Framework installed on your machine."; }if (Request.Browser.Cookies == true) { Label6.Text = "This browser supports Cookies."; }else { Label6.Text = "This browser does not currently support Cookies."; }Label7.Text = "You are running version " + Request.Browser.EcmaScriptVersion.ToString() + " of ECMA Script."; if (Request.Browser.Frames == true) { Label8.Text = "This browser supports HTML Frames."; }else { Label8.Text = "This browser does not support HTML Frames."; }if (Request.Browser.JavaApplets == true) { Label9.Text = "This browser supports Java Applets."; }else { Label9.Text = "This browser does not support Java Applets."; }Label10.Text = Request.Browser.Type.ToString() + "." + Request.Browser.MinorVersion.ToString(); Label11.Text = Request.Browser.Platform; |
No comments:
Post a Comment