user3635349
user3635349

Reputation: 1

Check if Browser's JS is enabled or disabled in backend code in asp.net

I need to check whether my browser's JS is enabled or disabled from server side and write the code according to that. I analysed many forums but all solutions are given in script side and to use tag. But for the performance base, i need to handle the code from server side. My page is aspx file. I need to handle it in aspx.cs file.

Example:

if(js is enabled){
asp control 1 display...
}

if(js is disabled){
asp control 2 display...
}

If js is enabled class js is adding and if js is disabled class no-js is adding in my html automatically.

Please help me with this. Thanks.

Upvotes: 0

Views: 1094

Answers (1)

JunaidKirkire
JunaidKirkire

Reputation: 918

There is a class System.Web.HttpBrowserCapabilities which helps you to detect if JS is supported by the browser or not but not if it's enabled or disabled.

You can only detect it after the first page load via executing a script in the browser which sets some flag in the cookie. Then after a subsequent request, you can track if you want to render JS absent/present logic for that user.

Upvotes: 1

Related Questions