[英]How to use ClientScript.RegisterClientScriptBlock with Inline code?
[英]RegisterClientScriptBlock CDATA inline declarations
从aspx页面迁移到ascx控件时,我将大量的头文件包含到代码隐藏中,我一直将它们包装在RegisterClientScriptBlocks中,并使用linq来保持大型多行的整洁。
但是,已经注意到,内联声明<%serverside.code%>
现在未得到执行。
ClientScript.RegisterClientScriptBlock(GetType(Page), "test", <a><![CDATA[
<script type="text/javascript">
testValue = '<%=Page.Title%>';
</script>]]></a>, True)
产生;
<script type="text/javascript">
testValue = '<%=Page.Title%>';
</script>
为了解决这个问题,我以.Value结束了cdata块,并附加了代码变量,然后使用其余的多行语句开始了一个新的cdata块
ClientScript.RegisterClientScriptBlock(GetType(Page), "test", <![CDATA[
<script type="text/javascript">
testValue = ']]>.Value + Page.Title + <![CDATA[';
//more code
</script>
]]>.Value, True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.