Question

I'm moving significant amounts of header includes into codebehind when migrating from aspx pages into ascx controls, I've been wrapping them in RegisterClientScriptBlocks and using linq to keep the large multiline tidy.

However have noticed that the inline declarations <%serverside.code%> are now not getting executed.

ClientScript.RegisterClientScriptBlock(GetType(Page), "test", <a><![CDATA[
        <script type="text/javascript">
            testValue = '<%=Page.Title%>';
        </script>]]></a>, True)

Produces;

<script type="text/javascript">
  testValue = '<%=Page.Title%>';
</script>
Était-ce utile?

La solution

To solve this I ended the cdata block with a .Value and appended the code variable, then started a new cdata block with the rest of the multiline statement

ClientScript.RegisterClientScriptBlock(GetType(Page), "test", <![CDATA[
    <script type="text/javascript">
        testValue = ']]>.Value + Page.Title + <![CDATA[';
        //more code
    </script>
  ]]>.Value, True)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top