Archive for April, 2006

Checking for Javascript availability/support from ASP.NET 2.0

Posted in Microsoft.NET on April 10, 2006 by vasudevan

The other day I had to check whether clients have disabled javascript functionality on their browsers. There is no easy way in ASP.NET 2.0 to acheive that. I also searched the whole of MSDN but only found that .NET 2.0 has a built in HttpBrowserCapabilities class which only can tell whether the client’s browser has support for javascript or not. Later, I discovered that there is a simple and robust way of checking whether the client has disabled javsascript and redirect them to a meaningful error page which can list steps to re-enable javascript functionality specific to their browser.

Here is the code: (placed inbetween <body></body> tags).

<noscript><meta http-equiv=”Refresh” content=”0; URL=../Errors/BrowserError.aspx”/> </noscript>

ASP.NET 2.0 compiler will throw this error:

Cannot switch views: Validation (XHTML 1.0 Transitional): Element ‘meta’ cannot be nested within element ‘noscript’.

But, from what I have seen is it is perfectly ok to ignore this error.

Tip: If you have a master page that has several content pages, the clever approach is to put the code in .master page. Also, the error page can be a .htm file.

Advertisements