[CLOSED] Set Template in Code Behind

  1. #1

    [CLOSED] Set Template in Code Behind

    Hi, I'm running across a problem trying to create an XTemplate for a DataView from code behind.

    When I'm doing it in source view it looks like this:


    <Template runat="server">
    <Html>
    <ul class="">
    <tpl for=".">
    <li>{message}</li>
    </tpl>
    </ul>
    </Html>
    </Template>



    This works without problem. The JS generated looks like this
    html: ["<ul class=\"\">","<tpl for=\".\">","<li>{message}</li>","</tpl>","</ul>",""]

    But I require to create the template from Code Behind as I'm making a Custom Server Control, so I tried it like this:


    DataView.Template.Html = "<ul class=''><tpl for='.'><li>{message}</li></tpl></ul>"

    But this doesn't work. The LI gets generated alright, but the value to be subsistuted by "{message}"


    The generated HTML when setting template from code behind
    html: ["<ul class=''><tpl for='.'><li>{message}</li></tpl></ul>"]

    As you will note it's an array with a single element instead of multiple like the other. The data is fine. So I'm stumped on what to do next.
  2. #2

    RE: [CLOSED] Set Template in Code Behind

    Hmmm. I'm able to work around it like this:

    DataView.Template.Html = "..."; This property has to be set or Ext.Net will throw a runtime error 
    DataView.Template.CustomConfig.Add(new ConfigItem("html", "['<ul class=\"\">','<tpl for=\".\">','<li>{message}</li>','</tpl>','</ul>','']", ParameterMode.Raw));

    But this is kinda dirty
  3. #3

    RE: [CLOSED] Set Template in Code Behind

    Hi,

    Please do not use single quotes for the string in the XTemplate.
    try the following
    DataView.Template.Html = "<ul class=\"\"><tpl for=\".\"><li>{message}</li></tpl></ul>";
  4. #4

    RE: [CLOSED] Set Template in Code Behind

    Great. It works. Thanks for your quick response

Similar Threads

  1. Replies: 2
    Last Post: Feb 01, 2012, 6:56 AM
  2. [CLOSED] Rerun template on the fly
    By craig2005 in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Feb 14, 2011, 8:35 AM
  3. [CLOSED] \r and \n in template
    By PatrikG in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Oct 12, 2010, 1:27 PM
  4. [CLOSED] EXT MVC Template with IOC, DI, TDD etc.
    By tiramisu in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: May 12, 2010, 5:05 AM
  5. Replies: 1
    Last Post: Oct 29, 2008, 4:44 AM

Posting Permissions