Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
26
rated 0 times [  32] [ 6]  / answers: 1 / hits: 26015  / 15 Years ago, wed, may 20, 2009, 12:00:00

I am using a hidden field 'Isjsenabled' to detect whether Client's Javascript is enabled or disabled. If Javascript is enabled, Javascript function will be fired and it will set hidden field's value to 1.



I want to check the hidden value from server side Page_load. But the problem is Javascript gets fired after Page load.



Do you have any suggestion ?



Html Part



<script type=text/javascript>
$(function() {
$(#<%= Isjsenabled.ClientID %>).val(1);
});
</script>

<input id=Isjsenabled runat=server value =0 type=hidden />


Code Behind Part



protected void Page_Load(object sender, EventArgs e) {                
HtmlInputHidden hdn = this.FindControl(Isjsenabled) as HtmlInputHidden;
if (hdn != null)
if (hdn.Value != null && hdn.Value == 0)
Helper.SetCookie(IJE, 0);
else
Helper.SetCookie(IJE, 1);
}

More From » .net

 Answers
15

Without thinking too hard about the direction you're trying to go in, there is a little used tag that is supported by all browsers called NOSCRIPT.



<noscript>
<img src=http://myserver/notify_no_script.aspx style=display:none>
</noscript>


As you can see, the idea is to make the browser request an image but only if javascript is disabled. This page could set a session variable stating that the current client has no script capability that would be available to all code in the current session.



Or, you could follow your current methodology:



<noscript>
<input type=hidden name=noscript value=1>
</noscript>
<script><!--
document.writeline('<input type=hidden name=noscript value=0>');
//--></script>


Hope this helps,



-Oisin


[#99498] Friday, May 15, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
analiseb

Total Points: 252
Total Questions: 96
Total Answers: 106

Location: Singapore
Member since Sat, Jul 25, 2020
4 Years ago
analiseb questions
;