Hezron Naresh Hezron Naresh - 1 year ago 58
ASP.NET (C#) Question

I need to detect if javascript is enabled or not in asp.net page load in c#

I have tried below code and it is detecting whether current request browser is supports to java script or not only. But my actual requirement is detect particular request browser that whether java script is enabled or disabled by the time request hit the page_load method

var request = HttpContext.Current.Request;
bool jsEnabled = request.Browser.JavaScript;

if (!jsEnabled)
javaScriptEnabled = false;

Answer Source

That's not possible, you're using a server side language, it does not access that kind of property when the user executes a request.

The client may provide some meta info through HTTP headers, but they don't necessarily tell you whether the user has JavaScript enabled or not and you can't rely on them anyway.

Source : Check if JavaScript is enabled with PHP

The only way to know it's on the client side using a <noscript></noscript> tag.

Besides , request.Browser.JavaScript tells you if the browser supports javascript, not if it's enabled.