Browser Capabilities and Client-Side Behavior


Server controls that contain client-side behavior should degrade gracefully into a more limited mode (usually into a server side “only mode) that preserves the core functionality of the control. This characteristic of server controls enables the page developer to write a single page that works across various browsers without having to write additional switching logic.

A server control should discover the capabilities of the requesting browser to determine whether the control can use its client-side functionality. ASP.NET encapsulates information about the requesting Web browser in an instance of the System.Web.HttpBrowserCapabilities object that can be retrieved by accessing the Browser property of the current HttpRequest object. This property is initialized by the ASP.NET runtime using the HTTP_USER_AGENT request header value sent by the Web browser to the server when the browser makes a request. As the name suggests, an HttpBrowserCapabilities object exposes properties that enable a server control to inspect the capabilities of the requesting browser and to determine when to activate its client-side functionality. Some especially useful properties of this object are MajorVersion , MinorVersion , MSDomVersion , and EcmaScriptVersion , which respectively indicate the version of the browser, its Document Object Model (DOM), and the version of ECMAScript available in the browser. A server control should inspect the properties of this object to render the appropriate content. A control can then support varied levels of client-side behavior based on the level of features available in the requesting Web browser.

In addition, a server control should offer the page developer a mechanism to turn off its client script features completely, regardless of the capabilities of the requesting browser. This functionality is typically implemented by providing a property such as EnableClientScript on the control, as the HtmlEditor control you'll see later in this chapter demonstrates .



Developing Microsoft ASP. NET Server Controls and Components
Developing Microsoft ASP.NET Server Controls and Components (Pro-Developer)
ISBN: 0735615829
EAN: 2147483647
Year: 2005
Pages: 183

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net