Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if Javascript is enabled server side ASP.NET

Is it possible to check if the client browser has javascript enabled from ASP.NET code?

I was hoping to ideally do this on PreRender of controls, or PageLoad, so that I can change how they look.

Any suggestions, work arounds etc would be much appreciated.

like image 203
Fermin Avatar asked Jun 04 '09 15:06

Fermin


People also ask

How can check JavaScript is enabled or not in asp net c#?

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.

How do I know if JavaScript is disabled?

On the web browser menu click on the "Edit" and select "Preferences". In the "Preferences" window select the "Security" tab. In the "Security" tab section "Web content" mark the "Enable JavaScript" checkbox. Click on the "Reload the current page" button of the web browser to refresh the page.

Is JavaScript on the server side or client side?

JavaScript is a client-side script, meaning the browser processes the code instead of the web server. Client-side scripts are commonly used when we want to validate data before sending it to the web server, adjusting the interface in response to user feedback, and for implementing other advanced features.


1 Answers

You can't do it, without making a subsequent request I'm afraid.

There are explanations that can be found by doing a search on Google most use an AJAX call or a hidden field that gets popluated via some javascript, that won't get run if Javascript is disabled.

If you have to do it then I'd try doing it on the very first request from the client, and save a cookie (or somethign similar), then check the value of the cookie on subsequent requests. This assumes that the user doesn't enable / disable Javascript often. You could also store a value in the session.

I hope that helps

like image 158
Lewis Avatar answered Oct 23 '22 09:10

Lewis