[CLOSED] Dynamically created TemplateColumn and template not script not rendered correctly.

  1. #1

    [CLOSED] Dynamically created TemplateColumn and template not script not rendered correctly.

    Hello,
    I am dynamically building a grid adding columns based on a configuration. This worked like a charm until today, when we had the requirement to add some <TemplateColumn/> columns too.

    The grid is on the ASPX page with a "base" markup that is changed server-side by adding the columns, properties, and so on.

    The TemplateColumn is configured by setting the "Column.Template.Html" property to the required template:

    For the sake of a test we put a sample string right now "<div>Test</div>".

        ' add column on grid.
                    Dim cfg As Ext.Net.Column.Config
                    Dim c As Ext.Net.Column
    
                    If col.Template IsNot Nothing Then
                        ' template column.                    
                        cfg = New Ext.Net.TemplateColumn.Config()
                    Else
                        ' normal column.
                        cfg = New Ext.Net.Column.Config()
                    End If
    
                    ' configure standard column properties.
                    With cfg
                        .ColumnID = col.ID
                        .DataIndex = String.Format("c{0}", col.Index)
                        .Width = col.Width
                        .Header = col.Description
                        .Hidden = Not col.Visible
                    End With
    
                    If col.Template IsNot Nothing Then
                        ' template column.
                        Dim templateColumn = New Ext.Net.TemplateColumn(cfg)                    
                        templateColumn.Template.Html = "<div>test</div>"                
                        c = templateColumn
                    Else
                        c = New Ext.Net.Column(cfg)
                    End If
    Unfortunately when we run the application we are not able to see anything and we saw a Javascript error that, very clearly state that the "tpl" property is mapped to a "javascript" clientinit function that's not present on the page:

    ... {dataIndex:"c2",header:"Subject",id:"Subject",widt h:-1,xtype:"templatecolumn",tpl:{body_ctl09_ClientInit}} ...

    However, that client side script "body_ctl09_ClientInit" is not found at all...

    It appears that "ClientInit" scripts are not rendered at all.
    Is there a special process to add columns at server side so that client init scripts are dumped to the client?

    Thank you!
    Last edited by Daniil; Jan 25, 2013 at 7:27 AM. Reason: [CLOSED]
  2. #2
    Hi @adrianot,

    I am unable to reproduce with the test case below.

    Please provide your full test case.

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.GridPanel1.GetStore();
                store.DataSource = new object[] 
                { 
                    new object[] { "test1", "test2", "test3" },
                    new object[] { "test4", "test5", "test6" },
                    new object[] { "test7", "test8", "test9" },
                };
                store.DataBind();
            }
        }
    
        protected void AddColumn(object sender, DirectEventArgs e)
        {
            this.GridPanel1.AddColumn(new Ext.Net.TemplateColumn()
                {
                    Header = "New Column",
                    DataIndex = "test1",
                    Template =
                    {
                        Html = "<b>{test1}</b>"
                    }
                });
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
                <Store>
                    <ext:Store runat="server">
                        <Reader>
                            <ext:ArrayReader>
                                <Fields>
                                    <ext:RecordField Name="test1" />
                                    <ext:RecordField Name="test2" />
                                    <ext:RecordField Name="test3" />
                                </Fields>
                            </ext:ArrayReader>
                        </Reader>
                    </ext:Store>
                </Store>
                <ColumnModel runat="server">
                    <Columns>
                        <ext:Column Header="Test1" DataIndex="test1" />
                        <ext:Column Header="Test2" DataIndex="test2" />
                        <ext:Column Header="Test3" DataIndex="test3" />
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>
            <ext:Button runat="server" Text="AddColumn" OnDirectClick="AddColumn" />
        </form>
    </body>
    </html>
  3. #3
    Hi Daniil, and sorry for my late reply. Finally I managed to resolve the issue.

    I was getting crazy trying to reproduce the issue, but I think I've found the actual reason.

    Our application builds the entire grid dynamically (store included), and does this on the MVC "view" using Web Forms view-type. We implemented this by running a server side <% %> script just before declaring the server controls. This worked fine for the "standard" columns, but as soon as we introduced the templated ones some ASP.NET-page lifecycle issue started to come out.

    In order to fix the issue, I had to map the "Page_Load" event, and apply the control "configuration" right there. The templates started to work like a charm.


    For this reason, we can consider this topic closed.
    Thanks!

Similar Threads

  1. [CLOSED] Label not rendered correctly inside Toolbar
    By smart+ in forum 1.x Premium Help
    Replies: 2
    Last Post: Dec 14, 2011, 5:58 AM
  2. [CLOSED] FileUpload in toolbar not rendered correctly
    By smart+ in forum 1.x Premium Help
    Replies: 2
    Last Post: Jan 31, 2011, 4:32 PM
  3. [CLOSED] [1.0] TopBar/ BottomBar not rendered correctly
    By klaus.schwarz in forum 1.x Premium Help
    Replies: 8
    Last Post: Oct 28, 2010, 9:09 AM
  4. Replies: 3
    Last Post: Oct 20, 2010, 3:37 PM
  5. Replies: 1
    Last Post: Jan 21, 2009, 12:46 PM

Tags for this Thread

Posting Permissions