admin管理员组文章数量:1389903
I need to use the tag in ASP.NET in order to call a C# method from the code behind class, but it seems to be calling it irrespective of whether JavaScript is enabled or disabled. Other text inside the tags works as expected.
Below is the code I am using, is there something I am doing wrong?
Thanks
<noscript>
other text here
<% DisableTextBox("textBoxId"); %>
</noscript>
Solution TextBox was disabled server-side, and enabled client-side using the following JavaScript/jQuery:
$("#txtTotalQuantScore").prop("disabled", false);
I need to use the tag in ASP.NET in order to call a C# method from the code behind class, but it seems to be calling it irrespective of whether JavaScript is enabled or disabled. Other text inside the tags works as expected.
Below is the code I am using, is there something I am doing wrong?
Thanks
<noscript>
other text here
<% DisableTextBox("textBoxId"); %>
</noscript>
Solution TextBox was disabled server-side, and enabled client-side using the following JavaScript/jQuery:
$("#txtTotalQuantScore").prop("disabled", false);
Share
Improve this question
edited Nov 8, 2013 at 15:01
BAS
asked Nov 8, 2013 at 13:50
BASBAS
12011 bronze badges
2
- 1 The server-side won't know whether the client-side has javascript enabled before its been sent to the client.. – Curtis Commented Nov 8, 2013 at 13:52
- If the client doesn't have scripting enabled, most of the .NET framework client-side functionality is not going to work... – Tim Commented Nov 8, 2013 at 13:53
3 Answers
Reset to default 6The ASP.NET view engine knows nothing about the noscript
tag you've included.
All server side code will be executed by the server and the result written to the HTML page. The noscript
tag can not be used as a C# if statement.
If you want to disable something when Javascript isn't available you can do so client side.
One way would be to set the element in question to hidden in your CSS and then use Javascript to unhide it.
As @Jamie Dixon has described, what you are trying to do is not possible.
Looking at your method name, it appears you are trying to disable a textbox if the browser doesn't support javascript.
Therefore I would remend always disabling this textbox on the server-side, and enabling it with javascript on the client-side.
This way, only browsers supporting javascript will have the textbox enabled.
I would add you can detect server-side that a browser supports scripting, but there's no easy way to tell whether or not the user has enabled scripting.
You can resort to a trick like setting a value in a hidden field through a script (0 for no scripting, 1 for enabled, for example), but this isn't always reliable.
本文标签: javascriptInline C in ltnoscriptgt tagsStack Overflow
版权声明:本文标题:javascript - Inline C# in <noscript> tags - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744606583a2615392.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论