Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question

1 Answer 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

share|improve this answer
    
literal renders to <span> .. do you mean wrapping script block with some other tag right .. I was thinking the same .. thanks a lot –  Emre Aug 13 '10 at 9:47
    
@Emre literal not render to span ! They are empty, that why they called literal. try it, I have try it and its working. –  Aristos Aug 13 '10 at 9:53
    
yes it is .. but i used a placeholder instead... but thanks for the info .. thanks a lot :) –  Emre Aug 13 '10 at 10:43
    
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. –  Colin Jul 26 '12 at 9:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.