开发者

Escaping inline code block in Asp.Net template

I have a page where I wish to render the following html (a small JS template)-

<script type开发者_JS百科="text/html" id="lightbox-template">
 <div id="lightbox-background"></div>
 <div id="lightbox"><%= content %><div class="bottom"></div></div>
</script>

However, the Asp.NET preprocessor is picking up on the "<%=" tag and trying to interpret it. I wish to escape this tag to allow it to be rendered, preferably from the template rather than the code behind. Is this possible?

I have managed to do this via a Literal control and setting it's text in the code behind.


I ideally wanted to keep it within the aspx page. This is the best solution I could find (from here), which creates splits the closing > into a separate string

<script type="text/html" id="lightbox-template">
 <div id="lightbox-background"></div>
 <div id="lightbox"><%= "<%= content %" + ">" %=><div class="bottom"></div></div>  
</script>

Important bit: <%= "<%= content %" + ">" %=>


This goes into aspx

<div> <%= GetContentString() %>  </div>

This goes into aspx.cs

 protected String GetContentString()
    {
        return "this is a content";
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜