![](/img/trans.png)
[英]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.