2

I have js script block (very long one that does editing capabilities to an invoice page).

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. But I quickly realized that saying runat="server" to client-side code was a real bad idea :)

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

literal renders to <span> .. do you mean wrapping script block with some other tag right .. I was thinking the same .. thanks a lot
@Emre literal not render to span ! They are empty, that why they called literal. try it, I have try it and its working.
yes it is .. but i used a placeholder instead... but thanks for the info .. thanks a lot :)
Using a literal gave me a compile error: "System.Web.UI.WebControls.Literal' does not allow child controls". But the PlaceHolder worked for me. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.