简体   繁体   English

如何禁用客户端脚本块服务器端(asp.net)

[英]Howto disable client script block server side (asp.net)

I have js script block (very long one that does editing capabilities to an invoice page). 我有js脚本块(很长的一个脚本块,可以对发票页面进行编辑)。

I want to enable/disable this functionality on the server-side. 我想在服务器端启用/禁用此功能。 First thing popped up on my mind was to say runat="server" to the tag, and set visible=true/false to asp.net, thinking asp.net does not render the HTML for non-visible items, so the block wouldn't load at all, which was what I wanted. 我想到的第一件事是对标签说runat =“ server”,然后将asp.net设置visible = true / false,以为asp.net不会为非可见项呈现HTML,因此该块不会根本没有加载,这就是我想要的。 But I quickly realized that saying runat="server" to client-side code was a real bad idea :) 但是我很快意识到,对客户端代码说runat =“ server”是一个糟糕的主意:)

What ar emy options, besides loading script from client side. 除了从客户端加载脚本之外,还有什么可选的选项。 Cuz I have other buttons that come from the server-that will enable dieable too ... If I use js for them the code will be ugly ... Thanks in advance 因为我还有其他来自服务器的按钮-也将启用死亡...如果我为他们使用js,代码将很难看...在此先感谢

Try this trick 试试这个技巧

<asp:Literal run="server" id="MyScriptBlock" EnableViewState="false">

     here type what ever you like

</asp:Literal>

and just make Visible or not the MyScriptBlock 并显示或不显示MyScriptBlock

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM