views:

274

answers:

2

I've got some custom templated controls which take JavaScript as template content, like so:

<ns:Custom runat="server">
  <contentTemplate>
    var a = new Array();
    for (var i=0; i<a.length; i++) {
      // do something
    }
  </contentTemplate>
</ns:Custom>

I want VisualStudio to treat the content of exactly the same as it does elements so that code coloring take effect and the validator doesn't puke on the "<" in the for-loop definition.

My understanding is that a custom DTD needs to be created to solve this. Does anybody know how to do this, have have links to resources for it?

Thanks!

A: 

I haven't been able to get this to work yet... this is what I have so far:

<xs:element name="methods">
    <xs:complexType>
         <xs:simpleContent>
            <xs:extension base="xs:string" />
         </xs:simpleContent>
    </xs:complexType>
</xs:element>

This doesn't seem to affect the way VisualStudio treats my control. Can you see anything that I'm doing wrong?

A: 

I admit I'm not familiar with VS templated controls, but this looks like XML (given the "ns:" namespace), and the standard way to embed left angle brackets inside XML, without them being treated as tags, is with CDATA:

<ns:Custom runat="server">
  <contentTemplate>
    <![CDATA[
      var a = new Array();
      for (var i=0; i<a.length; i++) {
        // do something
      }
    ]]>
  </contentTemplate>
</ns:Custom>
Joe White