+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Reference a resource in a custom control template

Reference a resource in a custom control template

22 posts, 0 answered
  1. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    13 May 2010
    Link to this post
    hello Sitefinity team

    I am busy with the development of a custom control to be used in the Sitefinity environment. This control makes use of a template

    When I want to use a resource reference in the Template like

    <asp:Label ID="lblOrderID" runat="server" AssociatedControlID="txtOrderID" Text="<%$ Resources:OrderID %>"></asp:Label>

    I get the error :
    Could not find any resources appropriate for the specified culture or the neutral culture.  Make sure "WebControls.Resources.Messages.resources" was correctly embedded or linked into assembly "WebControls" at compile time, or that all the satellite assemblies required are loadable and fully signed.

    I tried different things (ie. in the Resources folder the App_LocalResources with the templatename.ascx.resx file) but was not able yet to define the resource in the correct way so that it can be found.

    I am able to reference it programmatically (lblOrderID.Text = resman.GetString("OrderID")) but that is a lot of extra program work. Have you an idea how I can make this work by defining it in the ascx template?

    Hope you can help

    Kind regards
    Luc Baeten

  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    13 May 2010
    Link to this post
    Hi Luc Baeten,

    Thank you for using our services.

    If you are building your control in a class library instead of adding it in App_Code, and your control uses an embedded template you have to create a Messages.resx file which will contain the resources. You have to set the build action for this file to be Embedded Resource. Attached is a small sample which illustrates how it should be done.

    Kind regards,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    13 May 2010
    Link to this post
    hello Radoslav

    That was exactly the info I was looking for. Thank you very much

    regards
    Luc
  4. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    13 May 2010
    Link to this post
    hi Radoslav

    Developing further I encountered another problem. I also defined a designer template to configure the custom control in a user friendly way in Sitefinity.

    I defined the resources ('OrderProductListDesigner_lblOrderID' ) in the Messages.resx file for the designer template as well. But when I try to open the custom control in edit mode (so opening the designer template) in Sitefinity, I get the error
    'The resource object with key 'OrderProductListDesigner_lblOrderID' was not found.'.

    Should I define the resources for the designer template in another way?

    Kind regards
    Luc
  5. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    13 May 2010
    Link to this post
    Hi Luc Baeten,

    The method is exactly the same if you are going to use an embedded template for the designer. See attached project.

    Regards,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  6. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    14 May 2010
    Link to this post
    Hello Radoslav

    I defined a sperate container class in the designer as described in the webinar 'Create highly usable and distributable control'. Probably it should be possible to use the messages resource also with a separate container class but this is much easier. It works perfect.

    Many thanks for your quick response.

    regards
    Luc
  7. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    19 May 2010
    Link to this post
    Hello Radoslav

    The custom control is becoming more complex now. In the custom control Template I defined a RadWindow. In the ContentTemplate of this RadWindow a RadGrid is defined. With other words a RadGrid inside a RadWindow.

    I am able to open the radwindow and fill the radgrid with records. But whenever I try to edit a record in the radgrid or add a new one or press the refresh button in the RadGrid header (command item), the radwindow is closed without any changes.
    This must have something to do with Ajax because I define the same functionality of the custom control on a normal aspx page where I first had the same problem. After adding an AjaxManager to the page with Ajaxsettings for the RadGrid everything worked fine. I was able to edit the records in the RadGrid insed the RadWindow. After all changes I could close the RadWindow by clicking the Close icon of the RadWindow.

    I tried to define different Ajax scenarios for my custom control (RadAjaxManager, RadAjaxPanel, RadAjaxProxy) but was not able to solve it.
    An option would be that I open another RadWindow for editing RadGrid records like demonstrated in the Telerik examples. But I don't like to have two popup windows after each other.

    Hope you can help

    Kind regards
    Luc
  8. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    19 May 2010
    Link to this post
    Hello Luc Baeten,

    In the way that you are describing the scenario I get the impression that the markup which the RadWindow has to display is defined inline in your custom control template. When using controls with Ajax in Sitefinity you have to use RadAjaxManagerProxy on your control and RadAjaxManager on the top level page - this would be your master page. I suppose you are aware of the use of the proxy control.

    You can try another approach - to create a regular .aspx page and put your RadGrid there (instead of defining the RadGrid inline of the content template of the window). Then this .aspx page will be your top level page inside the window, so you can use AjaxManager as in one level page scenario. You can set the RadWindow to point to your page using NavigateUrl property.

    Best wishes,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  9. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    19 May 2010
    Link to this post
    Hello Radoslav

    Thanks for the very quick response.
    Your described other approach I used first. But if possible I want to have all desired functionality in one custom control without separate aspx pages. Therefor I liked the way of defining the RadWindow inline in the custom control (not using the RadWindowManager)

    And yes I tried the usage of the RadAjaxManager in the masterpage and the RadAjaxProxy in the custom control. But I was not able to solve it this way till now?! Is this an approach that should work? Or will it never work the way I defined.

    Regards
    Luc
  10. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    19 May 2010
    Link to this post
    Hello Luc Baeten,

    Basically this way should work with AjaxManagerProxy. One thing to note is that if you use some client side code for getting the RadGrid control by its client id. Since the control is nested into another control the only way to get the control by client ID is:
    1) Expose a hidden field on the top of the control hierarchy and then pass the the RadGrid.ClientID on create child controls to the hidden field.
    2) Create your control to be IScriptControl and pass the client ID using the approach discussed in this blog post.

    Other than that I think I am not able to suggest anything further unless I have access to the custom control code to run it locally.

    Kind regards,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  11. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    19 May 2010
    Link to this post
    Hello Radoslav

    This is part of the code of the control template I defined. As you can see I removed part of the code for simplifying

    <telerik:RadWindow ID="wndSalesPersons" runat="server" Title="Verkopers" Width="450"
        OnClientActivate="OnClientActivate" Height="350" VisibleOnPageLoad="false" Modal="true"
        Behaviors="Close" OpenerElementID="btnSalesPerson" Skin="Windows7">
        <ContentTemplate>
            <div style="padding-top: 10px; text-align: center;">
                <telerik:RadGrid ID="grdSalesPersons" runat="server" AllowAutomaticDeletes="True"
                    AllowAutomaticInserts="true" AllowAutomaticUpdates="true"
                    Skin="Windows7" AllowPaging="True" Width="99%" DataSourceID="sqlSalesPersonDataSource">
                    <PagerStyle Mode="NumericPages" />
                    <MasterTableView AutoGenerateColumns="False" DataKeyNames="verkoperid" ClientDataKeyNames="verkoperid,voornaam,achternaam"
                        Width="100%" PageSize="25" CommandItemDisplay="Top" DataSourceID="sqlSalesPersonDataSource">
                        <Columns>
                        </Columns>
                        <CommandItemSettings AddNewRecordText="Add new education" RefreshText="Refresh" />
                    </MasterTableView>
                    <ClientSettings>
                        <Selecting AllowRowSelect="true" />
                    </ClientSettings>
                </telerik:RadGrid>
                <asp:SqlDataSource ID="sqlSalesPersonDataSource" runat="server">
                </asp:SqlDataSource>
            </div>
        </ContentTemplate>
    </telerik:RadWindow>
    <telerik:RadAjaxManagerProxy ID="ajxManagerProxy" runat="server">
    </telerik:RadAjaxManagerProxy>

    And this is part of the custom control class code

    /// <summary>
    /// Initalize the used child controls in the Order Product List custom control
    /// </summary>
    /// <param name="controlContainer">Main custom control</param>
    protected override void InitializeControls(Control controlContainer)
    {
        //add other logic here
        base.InitializeControls(controlContainer);
      
        try
        {
      
            ..............
      
            //Initialize the input fields
            wndSalesPersons.OpenerElementID = btnSalesPerson.ClientID;
      
         //Define RadGrid itemcreated EventHandler
            grdSalesPersons.ItemCreated += new GridItemEventHandler(grdSalesPersons_OnItemCreated);
      
            //define connectionstring that points to the correct database
            sqlSalesPersonDataSource.ConnectionString = ConfigurationManager.ConnectionStrings[GridConnectionString].ConnectionString;
      
            ajxManagerProxy.AjaxSettings.AddAjaxSetting(grdSalesPersons, grdSalesPersons);
      
      
            ........
      
        }
        catch (Exception ex)
        {
        }
      
    }
      
    ...........................
      
    protected virtual RadWindow wndSalesPersons
    {
        get
        {
                return base.Container.GetControl<RadWindow>("wndSalesPersons", true);
        }
    }
      
    protected virtual RadGrid grdSalesPersons
    {
        get
        {
      
                return (RadGrid)wndSalesPersons.ContentContainer.FindControl("grdSalesPersons");
        }
    }
      
    protected virtual SqlDataSource sqlSalesPersonDataSource
    {
        get
        
                return (SqlDataSource)wndSalesPersons.ContentContainer.FindControl("sqlSalesPersonDataSource");
        }
    }
      
    protected virtual RadAjaxManagerProxy ajxManagerProxy
    {
        get
        {
                return base.Container.GetControl<RadAjaxManagerProxy>("ajxManagerProxy", true);
        }
    }

    As you can see I reference all controls, used in the control template, via base.Container.GetControl and RadWindow.ContentContainer.FindControl

    The window is opened via OpenerElementID. This works fine. Also the RadGrid is filled based on the defined SqlDataSource. I defined the AjaxSettings programmatically for the AjaxManagerProxy also.
    I thought this way I defined the correct ClientID of the RadGrid for the AjaxManagerProxy ?!

    regards
    Luc
  12. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    20 May 2010
    Link to this post
    Hello Luc Baeten,

    In your code you have wrapped the InitializeControls code with try catch. This is preventing you to see that the Ajax manager cannot properly add the Ajax setting because the page on which the Ajaxified control resides is returning null - the RadWindow content template. To properly add the Ajax setting you have to do this either in the Init or Load event of the window's content template. I have attached sample control which does this.

    Kind regards,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  13. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    25 May 2010
    Link to this post
    Hello Radoslav

    I knew that the try catch captured the undefined Page. In fact I defined the AddAjaxSetting first in the OnPreRender event and used the Proxy control instead of the manager like you did. Afterwards I tried a lot of other things such as adding it in the InitializeControls function. Without succes.

    But with your sample code I was able to create our control exactly as I wanted. Thank you very much for your support

    regards
    Luc
  14. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    09 Sep 2010
    Link to this post
    Hello Radoslav

    I keep struggling with using a RadGrid in a custom control. I defined a new control (and used the code you defined as sample) but I am not able to edit the grid items. This is what I have:

    ascx

    <%@ Control Language="C#" AutoEventWireup="true" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <div id="MainCommentsList" runat="server">
        <telerik:RadAjaxManagerProxy ID="ajxManagerProxy" runat="server">
        </telerik:RadAjaxManagerProxy>
        <telerik:RadAjaxLoadingPanel runat="server" ID="ajxCommentsLoadingPanel" Skin="Vista">
        </telerik:RadAjaxLoadingPanel>
        <telerik:RadAjaxPanel ID="ajxCommentsPanel" runat="server" LoadingPanelID="ajxCommentsLoadingPanel"
            EnableAJAX="true">
            <div style="padding-top: 10px; text-align: center;">
                <telerik:RadGrid ID="grdComments" runat="server" AllowAutomaticDeletes="True" AllowAutomaticInserts="true"
                    AllowAutomaticUpdates="true" Skin="Windows7" AllowPaging="True" Width="99%">
                    <PagerStyle Mode="NumericPages" />
                    <MasterTableView AutoGenerateColumns="False" DataKeyNames="ID" Width="100%" PageSize="25"
                        CommandItemDisplay="Top">
                        <Columns>
                            <telerik:GridButtonColumn HeaderStyle-Width="50" ItemStyle-Width="50" ItemStyle-HorizontalAlign="Right"
                                ConfirmText="<%$ Resources:CommentsList_DeleteComment %>" CommandName="Delete"
                                Text="<%$ Resources:CommentsList_btnDelete %>" UniqueName="DeleteColumn">
                            </telerik:GridButtonColumn>
                            <telerik:GridBoundColumn DataField="ID" HeaderText="ID" ReadOnly="True" Visible="false"
                                SortExpression="ID" UniqueName="ID">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Title" HeaderText="<%$ Resources:CommentsList_Title %>"
                                SortExpression="Title" UniqueName="Title">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="DefinedBy" HeaderText="<%$ Resources:CommentsList_DefinedBy %>"
                                SortExpression="DefinedBy" UniqueName="DefinedBy">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="AssignedTo" AllowFiltering="false" HeaderText="<%$ Resources:CommentsList_AssignedTo %>"
                                SortExpression="AssignedTo" UniqueName="AssignedTo">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="StatusID" HeaderText="Status" SortExpression="<%$ Resources:CommentsList_Status %>"
                                UniqueName="StatusID">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="PriorityID" HeaderText="<%$ Resources:CommentsList_Priority %>"
                                SortExpression="PriorityID" UniqueName="PriorityID">
                            </telerik:GridBoundColumn>
                            <telerik:GridEditCommandColumn>
                            </telerik:GridEditCommandColumn>
                        </Columns>
                        <EditFormSettings EditFormType="Template">
                            <FormTemplate>
                                <table id="Table2" cellspacing="2" cellpadding="1" width="100%" border="0" rules="none"
                                    style="border-collapse: collapse; background: white;">
                                    <tr>
                                        <td colspan="2">
                                            <b>Comments Info:</b>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <table id="Table3" cellspacing="1" cellpadding="1" width="250" border="0" class="module">
                                                <tr>
                                                    <td>
                                                        Title:
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind( "Title" ) %>'>
                                                        </asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        DefinedBy:
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind( "DefinedBy") %>' TabIndex="1">
                                                        </asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        AssignedTo:
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="TextBox9" runat="server" Text='<%# Bind( "AssignedTo") %>' TabIndex="2">
                                                        </asp:TextBox>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>
                            </FormTemplate>
                        </EditFormSettings>
                        <CommandItemSettings AddNewRecordText="<%$ Resources:CommentsList_AddComment %>"
                            RefreshText="Refresh" />
                    </MasterTableView>
                    <ClientSettings>
                        <Selecting AllowRowSelect="true" />
                    </ClientSettings>
                </telerik:RadGrid>
            </div>
        </telerik:RadAjaxPanel>
    </div>


    code behind

    using System;
    using System.ComponentModel;
    using System.Configuration;
    using System.Reflection;
    using System.Resources;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using Telerik.Framework.Web.Design;
    using Telerik.Web.UI;
    using System.Data;
    using System.Web;
    using System.Globalization;
    using System.Text;
    using System.Collections.Generic;
    using Milestre.WebControls.DataAccessClasses;
      
    namespace Milestre.WebControls.WebClasses
    {
        [ControlDesigner("Milestre.WebControls.DesignerClasses.CommentsListDesigner")]
        public class CommentsList : Telerik.Cms.Web.UI.SimpleControl
        {
      
            /// <summary>
            /// Initalize the used child controls in the Order Product List custom control
            /// </summary>
            /// <param name="controlContainer">Main custom control</param>
            protected override void InitializeControls(Control controlContainer)
            {
                //In edit mode the page is null
                if (Page == null || DesignMode)
                {
                    MainCommentsList.Visible = false;
                    Label noDesignModeLabel = new Label();
                    noDesignModeLabel.Text = "The control, Milestre.WebControls.CommentsList, cannot be viewed in design mode";
                    noDesignModeLabel.Font.Italic = true;
                    controlContainer.Controls.Add(noDesignModeLabel);
                }
                else
                {
                    //add other logic here
                    base.InitializeControls(controlContainer);
      
                    try
                    {
                        //Initialize the stylesheet. If true the embedded stylesheet will be used
                        if (UseEmbeddedStyles)
                            EmbedStyles();
      
                        //Initialize the stylesheet class. If not defined the default (Milestre_CommentsList) will be used
                        MainCommentsList.Attributes.Add("Class", CssClass);
      
                        ajxCommentsPanel.Init += new EventHandler(ajxCommentsPanel_Init);
      
                        grdComments.ItemCommand += new GridCommandEventHandler(grdComments_ItemCommand);
      
                        CachedCommentsData.ConnectionString = ConnectionString;
      
                        grdComments.DataSource = CachedCommentsData.GetComments();
                        grdComments.Rebind();
                    }
                    catch (Exception ex)
                    {
                        throw;
                    }
                }
      
            }
      
            void ajxCommentsPanel_Init(object sender, EventArgs e)
            {
                RadAjaxManager ajaxManager = RadAjaxManager.GetCurrent(this.Page);
                if (ajaxManager != null)
                    ajaxManager.AjaxSettings.AddAjaxSetting(grdComments, ajxCommentsPanel, ajxCommentsLoadingPanel);
            }
      
            /// <summary>
            /// Handles adding a stylesheet reference to the page's <head> tag        
            /// </summary>        
            private void EmbedStyles()
            {
                // Getting my own reference to System.Web.UI.Page to ensure it exists.            
                // Using this.Page instead will result in a null object in the Sitefinity Page Editor.            
                var page = (System.Web.UI.Page)System.Web.HttpContext.Current.Handler;
                HtmlLink link = new HtmlLink();
                link.Href = page.ClientScript.GetWebResourceUrl(this.GetType(), "Milestre.WebControls.Resources.CommentsList.css");
                link.Attributes.Add("type", "text/css");
                link.Attributes.Add("rel", "stylesheet");
                page.Header.Controls.Add(link);
            }
      
            protected void grdComments_ItemCommand(object source, GridCommandEventArgs e)
            {
                if (e.CommandName == RadGrid.InitInsertCommandName) //"Add new" button clicked
                {
                    GridEditCommandColumn editColumn = (GridEditCommandColumn)grdComments.MasterTableView.GetColumn("EditCommandColumn");
                    editColumn.Visible = false;
                }
                else if (e.CommandName == RadGrid.RebindGridCommandName && e.Item.OwnerTableView.IsItemInserted)
                {
                    e.Canceled = true;
                }
                else
                {
                    GridEditCommandColumn editColumn = (GridEditCommandColumn)grdComments.MasterTableView.GetColumn("EditCommandColumn");
                    if (!editColumn.Visible)
                        editColumn.Visible = true;
                }
            }
      
            /// <summary>
            /// Define Template for custom control
            /// </summary>
            public override string LayoutTemplateName
            {
                get
                {
                    return layoutTemplateName;
                }
            }
      
            [WebSysTemplate(layoutTemplateName, "This is a description", "~/Templates/CommentsList.ascx", true, "2010-04-15")]
            public override string LayoutTemplatePath
            {
                get
                {
                    return base.LayoutTemplatePath;
                }
                set
                {
                    base.LayoutTemplatePath = value;
                }
            }
      
            public override Type LocalizationAssemblyInfo
            {
                get
                {
                    return base.LocalizationAssemblyInfo;
                }
                set
                {
                    base.LocalizationAssemblyInfo = value;
                }
            }
      
            protected virtual HtmlControl MainCommentsList
            {
                get
                {
                    return base.Container.GetControl<HtmlControl>("MainCommentsList", true);
                }
            }
      
            protected virtual RadAjaxPanel ajxCommentsPanel
            {
                get
                {
                    return base.Container.GetControl<RadAjaxPanel>("ajxCommentsPanel", true);
                }
            }
      
            protected virtual RadAjaxLoadingPanel ajxCommentsLoadingPanel
            {
                get
                {
                    return base.Container.GetControl<RadAjaxLoadingPanel>("ajxCommentsLoadingPanel", true);
                }
            }
      
            protected virtual RadGrid grdComments
            {
                get
                {
                    return base.Container.GetControl<RadGrid>("grdComments", true);
                }
            }
      
            [
            Category("Comments List Appearance"),
            Description("If set to true the CSS Class specified is activated, false then the default is displayed.")
            ]
            public bool UseEmbeddedStyles
            {
                get
                {
                    return _useembeddedstyles;
                }
                set
                {
                    _useembeddedstyles = value;
                }
            }
      
            [
            Category("Comments List Appearance"),
            Description("CSS Class name applied to the control.")
            ]
            public override string CssClass
            {
                get
                {
                    return _cssClass;
                }
                set
                {
                    _cssClass = value;
                }
            }
      
            [
            Category("Comments List Data"),
            Description("Connection")
            ]
            public string ConnectionString
            {
                get { return _connectionString; }
                set { _connectionString = value; }
            }
      
            private string _cssClass = "Milestre_CommentsList";
            private bool _useembeddedstyles = true;
            private string _connectionString = "mlConnectionString";
      
            protected const string layoutTemplateName = "Milestre.WebControls.Templates.CommentsList.ascx";
      
        }
    }

    I am not able to solve the problem of editing the items in the grid with the defined Form Template. After searching hours for solving the error that RadGrid doesn't support the PageStyle property (After redefinition of the ascx the problem was gone????)l I get this error now: 'A control with ID 'grdComments' could not be found for the trigger in UpdatePanel 'ajxCommentsPanelPanel'. ' Line 74 of Code behind (

    ajaxManager.AjaxSettings.AddAjaxSetting(grdComments, ajxCommentsPanel, ajxCommentsLoadingPanel);

    )

    I have no idea why? Could you help me again? Thanks in advance.

    regards
    Luc


  15. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    09 Sep 2010
    Link to this post
    Hello Luc Baeten,

    Could you please break point this line and when you hit the break point see if the grdComments object is returning null?

    Regards,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  16. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    09 Sep 2010
    Link to this post
    Hi Radoslav

    No the grdComments is not null

    Regards
    Luc
  17. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    14 Sep 2010
    Link to this post
    Hello Luc Baeten,

    I am unable to recreate the behavior of your control locally due to missing dependent libraries. I have tried to create a small control which behaves similarly however I have not been able to recreate the problem. Do you get the error on initial load of the control or you get it when some Ajax request occurs and the control needs to be recreated. Probably you can zip up a sample project with db and send it to us. We will run it locally and see what might be going on.

    Greetings,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  18. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    13 Dec 2010
    Link to this post
    Hello Radoslav

    Based on your info I was able to create a custom control that was working with the RadAjaxPanel. This is the template definition.

    <%@ Control Language="C#" AutoEventWireup="true" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <div id="MainOrderList" runat="server">
        <div class="OrderListHeader">
            <div class="OrderProductHead">
            </div>
            <div class="OrderProductExpHead">
            </div>
        </div>
        <div class="OrderListData">
            <telerik:RadAjaxLoadingPanel runat="server" ID="ajxLoadingPanel" Transparency="5">
                <asp:Image ID="imgLoadingPanel" BorderWidth="0px" AlternateText="Loading" Style="margin-left: 475px;"
                    runat="server"></asp:Image>
            </telerik:RadAjaxLoadingPanel>
            <telerik:RadAjaxPanel ID="ajxPanel" runat="server" LoadingPanelID="ajxLoadingPanel"
                EnableAJAX="true">
                <telerik:RadGrid ID="grdItOrders" runat="server" AllowSorting="True" AllowMultiRowSelection="False"
                    AllowPaging="True" PageSize="25" GridLines="None" EnableEmbeddedSkins="false"
                    Skin="GBdealer">
                    <PagerStyle Mode="NumericPages" />
                    <MasterTableView NoMasterRecordsText="<%$ Resources:OrderList_NoOrders %>" AutoGenerateColumns="false" AllowMultiColumnSorting="True" DataKeyNames="ItOrderID">
                        <Columns>
                            <telerik:GridBoundColumn SortExpression="ItOrderID" HeaderText="Order nr" HeaderButtonType="TextButton"
                                DataField="ItOrderID" UniqueName="ItOrderID">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn SortExpression="ItReference" HeaderText="Referentie" HeaderButtonType="TextButton"
                                DataField="ItReference" UniqueName="ItReference">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn SortExpression="ItOrderDate" DataFormatString="{0:dd/MM/yyyy}"
                                HeaderText="Besteldatum" HeaderButtonType="TextButton" DataField="ItOrderDate"
                                UniqueName="ItOrderDate">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn SortExpression="ItOrderDeliveryDate" DataFormatString="{0:dd/MM/yyyy}"
                                HeaderText="Leverdatum" HeaderButtonType="TextButton" DataField="ItOrderDeliveryDate"
                                UniqueName="ItOrderDeliveryDate">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn SortExpression="ItStatus" HeaderText="Status" HeaderButtonType="TextButton"
                                DataField="ItStatus" UniqueName="ItStatus">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn SortExpression="ItPrice" HeaderText="Prijs" HeaderButtonType="TextButton"
                                DataField="ItPrice" UniqueName="ItPrice" HeaderStyle-VerticalAlign="Top" HeaderStyle-HorizontalAlign="Right"
                                ItemStyle-VerticalAlign="Top" ItemStyle-HorizontalAlign="Right" DataFormatString="€ {0:N2}"
                                ItemStyle-Wrap="false">
                            </telerik:GridBoundColumn>
                        </Columns>
                        <NestedViewTemplate>
                            <asp:Panel runat="server" ID="OrderItemsContainer" CssClass="viewWrap">
                                <telerik:RadGrid ID="grdItOrderItems" runat="server" AllowPaging="True" EnableEmbeddedSkins="false"
                                    Skin="GBdealer">
                                    <MasterTableView AutoGenerateColumns="false" AllowMultiColumnSorting="True" DataKeyNames="ItOrderID">
                                        <Columns>
                                            <telerik:GridBoundColumn SortExpression="ItFollowNr" HeaderText="Nr" HeaderButtonType="TextButton"
                                                DataField="ItFollowNr" UniqueName="ItFollowNr" HeaderStyle-VerticalAlign="Top"
                                                ItemStyle-VerticalAlign="Top">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn SortExpression="ItProductName" HeaderText="Type" HeaderButtonType="TextButton"
                                                DataField="ItProductName" UniqueName="ItProductName" HeaderStyle-VerticalAlign="Top"
                                                ItemStyle-VerticalAlign="Top">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn SortExpression="ItDescription" HeaderText="Omschrijving"
                                                HeaderButtonType="TextButton" DataField="ItDescription" UniqueName="ItDescription"
                                                HeaderStyle-VerticalAlign="Top" ItemStyle-VerticalAlign="Top">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn SortExpression="ItWidth" HeaderText="Breedte" HeaderButtonType="TextButton"
                                                DataField="ItWidth" UniqueName="ItWidth" HeaderStyle-VerticalAlign="Top" HeaderStyle-HorizontalAlign="Right"
                                                ItemStyle-HorizontalAlign="Right" ItemStyle-VerticalAlign="Top">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn SortExpression="ItHeight" HeaderText="Hoogte" HeaderButtonType="TextButton"
                                                DataField="ItHeight" UniqueName="ItHeight" HeaderStyle-VerticalAlign="Top" HeaderStyle-HorizontalAlign="Right"
                                                ItemStyle-HorizontalAlign="Right" ItemStyle-VerticalAlign="Top">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn SortExpression="ItColor" HeaderText="Kleur" HeaderButtonType="TextButton"
                                                DataField="ItColor" UniqueName="ItColor" HeaderStyle-VerticalAlign="Top" ItemStyle-VerticalAlign="Top">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn SortExpression="ItPriceGroup" HeaderText="Prijsgroep" HeaderButtonType="TextButton"
                                                DataField="ItPriceGroup" UniqueName="ItPriceGroup" HeaderStyle-VerticalAlign="Top"
                                                ItemStyle-VerticalAlign="Top">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn SortExpression="ItPrice" HeaderText="Prijs" HeaderButtonType="TextButton"
                                                DataField="ItPrice" UniqueName="ItPrice" HeaderStyle-VerticalAlign="Top" HeaderStyle-HorizontalAlign="Right"
                                                ItemStyle-VerticalAlign="Top" ItemStyle-HorizontalAlign="Right" DataFormatString="€ {0:N2}"
                                                ItemStyle-Wrap="false">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn SortExpression="ItDeliveryDate" DataFormatString="{0:dd/MM/yyyy}"
                                                HeaderText="Verwachte verzenddatum" HeaderButtonType="TextButton" DataField="ItDeliveryDate"
                                                UniqueName="ItDeliveryDate" HeaderStyle-VerticalAlign="Top" ItemStyle-VerticalAlign="Top">
                                            </telerik:GridBoundColumn>
                                        </Columns>
                                        <NestedViewTemplate>
                                            <asp:Panel runat="server" ID="OrderItemContainer" CssClass="viewWrap">
                                                <asp:DetailsView ID="dtvOrderItemInfo" AllowPaging="true" GridLines="None" Width="100%"
                                                    runat="server" Font-Italic="true" AutoGenerateRows="false">
                                                    <Fields>
                                                        <asp:BoundField HeaderText="" DataField="ItFollowNr" />
                                                        <asp:BoundField HeaderText="" DataField="ItProductName" />
                                                        <asp:BoundField HeaderText="" DataField="ItDeliveryDate" DataFormatString="{0:MM/dd/yyyy}" />
                                                        <asp:BoundField HeaderText="" DataField="ItDescription" />
                                                        <asp:BoundField HeaderText="" DataField="ItNumber" />
                                                        <asp:BoundField HeaderText="" DataField="ItWidth" />
                                                        <asp:BoundField HeaderText="" DataField="ItHeight" />
                                                        <asp:BoundField HeaderText="" DataField="ItColor" />
                                                        <asp:BoundField HeaderText="" DataField="ItOperation" />
                                                        <asp:BoundField HeaderText="" DataField="ItOperationLength" />
                                                        <asp:BoundField HeaderText="" DataField="ItOperationSide" />
                                                        <asp:BoundField HeaderText="" DataField="ItSupport" />
                                                        <asp:BoundField HeaderText="" DataField="ItSupportNumber" />
                                                        <asp:BoundField HeaderText="" DataField="ItProd1" />
                                                        <asp:BoundField HeaderText="" DataField="ItProd2" />
                                                        <asp:BoundField HeaderText="" DataField="ItProd3" />
                                                        <asp:BoundField HeaderText="" DataField="ItProd4" />
                                                        <asp:BoundField HeaderText="" DataField="ItProd5" />
                                                        <asp:BoundField HeaderText="" DataField="ItProd6" />
                                                        <asp:BoundField HeaderText="" DataField="ItProd7" />
                                                        <asp:BoundField HeaderText="" DataField="ItPriceGroup" />
                                                        <asp:BoundField HeaderText="" DataField="ItPrice" DataFormatString="€ {0:N2}" />
                                                    </Fields>
                                                </asp:DetailsView>
                                            </asp:Panel>
                                        </NestedViewTemplate>
                                    </MasterTableView>
                                </telerik:RadGrid>
                            </asp:Panel>
                        </NestedViewTemplate>
                    </MasterTableView>
                </telerik:RadGrid>
            </telerik:RadAjaxPanel>
        </div>
        <div class="OrderListFooter">
        </div>
    </div>
    <div style="position: absolute; font-family: Arial; font-size: 8pt; color: White;
        top: 0px; right: 0px; width: 330px;">
        <asp:Label ID="lblDebug" runat="server" Text="" Visible="false"></asp:Label>
    </div>


    And this is part of the code behind

    /// <summary>
    /// Creating a OrderList Composite Control
    /// </summary>
    [DefaultProperty("ArticleBehaviour")]
    [ControlDesigner("GBdealer.WebControls.DesignerClasses.OrderListDesigner")]
    public class OrderList : Telerik.Cms.Web.UI.SimpleControl
    {
        /// <summary>
        /// Initalize the used child controls in the Order Product List custom control
        /// </summary>
        /// <param name="controlContainer">Main custom control</param>
        protected override void InitializeControls(Control controlContainer)
        {
            //In edit mode the page is null
            if (Page == null || DesignMode)
            {
                MainOrderList.Visible = false;
                Label noDesignModeLabel = new Label();
                noDesignModeLabel.Text = "The control, GBdealer.WebControls.WebClasses.OrderList, cannot be viewed in design mode";
                noDesignModeLabel.Font.Italic = true;
                controlContainer.Controls.Add(noDesignModeLabel);
            }
            else
            {
                //add other logic here
                base.InitializeControls(controlContainer);
                CachedData.ConnectionString = ConnectionString;
                //Check if you have a authenticated dealer
                Dealer dealer = new Dealer();
                ajxPanel.Init += new EventHandler(ajxPanel_Init);
                //Initialize the stylesheet class. If not defined the default (GBdealer_OrderProductList) will be used
                MainOrderList.Attributes.Add("Class", CssClass);
                grdItOrders.ItemCreated += new GridItemEventHandler(grdItOrders_ItemCreated);
                grdItOrders.ItemCommand += new GridCommandEventHandler(grdItOrders_ItemCommand);
                grdItOrders.DataSource = dealer.GetItOrders(Status);
                grdItOrders.DataBind();
            }
        }
        void ajxPanel_Init(object sender, EventArgs e)
        {
            RadAjaxManager ajaxManager = RadAjaxManager.GetCurrent(this.Page);
            if (ajaxManager != null)
            {
                ajaxManager.AjaxSettings.AddAjaxSetting(grdItOrders, grdItOrders, ajxLoadingPanel);
                imgLoadingPanel.ImageUrl = this.Page.ClientScript.GetWebResourceUrl(this.GetType(), "GBdealer.WebControls.Resources.loading.gif");
            }
        }

    When I define now  AllowFilteringByColumn="True" in the grdItOrders (and nothing else) I get an error:

    A control with ID 'grdItOrders' could not be found for the trigger in UpdatePanel 'grdItOrdersPanel'.

    Line 86:             if (ajaxManager != null)
    Line 87:             {
    Line 88: ajaxManager.AjaxSettings.AddAjaxSetting(grdItOrders, grdItOrders, ajxLoadingPanel);Line 89:                 imgLoadingPanel.ImageUrl = this.Page.ClientScript.GetWebResourceUrl(this.GetType(), "GBdealer.WebControls.Resources.loading.gif");
    Line 90:             }


    Have you any idea why this error occurs?

    Kind regards
    Luc Baeten
  19. Kedar
    Kedar avatar
    1 posts
    Registered:
    09 Dec 2010
    14 Dec 2010
    Link to this post
    Hi Telerik Team,
    We are having issue with implementing Radwindow (Radgrid in radwindow) in custom controls.
    The Radwindow is not showing up even though we have set the opener element ID for Radwindow.
    Let us know if we are missing anything here.
    protected override void CreateChildControls()
            {
     
                Panel PnlLookup = new Panel();
                PnlLookup.ID = "MainContainer";
     
                Label lblMsg = new Label();
                lblMsg.ID = "LblMsg";
     
                PnlLookup.Controls.Add(lblMsg);
     
                ImageButton btnClear = new ImageButton();
                btnClear.ID = "btnClear";
                btnClear.ImageUrl = "image url"
                //btnClear.Click+=new ImageClickEventHandler(btnClear_Click);
                PnlLookup.Controls.Add(btnClear);
     
                ImageButton btnPopup = new ImageButton();
                btnPopup.ID = "btnPopup";
                btnPopup.ImageUrl = @"image url";
                //btnPopup.Click+=new ImageClickEventHandler(btnPopup_Click);
                PnlLookup.Controls.Add(btnPopup);
     
                //   The PopUp window with the RadGrid
     
     
                RadWindowManager rwmManager = new RadWindowManager();
     
                RadWindow RadWindow1 = new RadWindow();
                RadWindow1.ID = "RadWindow1";
                RadWindow1.OpenerElementID = btnPopup.ClientID;
     
                RadWindow1.DestroyOnClose = true;
                RadWindow1.Modal = true;
                RadWindow1.AutoSize = true;
                RadWindow1.Top = 50;
                RadWindow1.Left = 60;
                RadWindow1.VisibleStatusbar = true;
                RadWindow1.RegisterWithScriptManager = true;
                RadWindow1.ShowContentDuringLoad = true;
     
                RadWindow1.ClientIDMode = System.Web.UI.ClientIDMode.AutoID;
                RadWindow1.InitialBehaviors = WindowBehaviors.None;
                //   The Rad Grid which displays the complete set of Rows
                RadGrid grdPopup = new RadGrid();
                grdPopup.ID = "grdPopup";
                grdPopup.AllowFilteringByColumn = true;
                grdPopup.AllowPaging = true;
                grdPopup.ViewStateMode = System.Web.UI.ViewStateMode.Enabled;
                grdPopup.AllowSorting = true;
                grdPopup.PageSize = 6;
                grdPopup.NeedDataSource+=new GridNeedDataSourceEventHandler(grdPopup_NeedDataSource);
                grdPopup.ClientSettings.EnableRowHoverStyle = true;
                grdPopup.ClientSettings.Selecting.AllowRowSelect = true;
                grdPopup.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
                grdPopup.GroupingSettings.CaseSensitive = false;
                if (!Page.IsPostBack)
                {
                    grdPopup.MasterTableView.DataKeyNames = new string[] { ValueMember };
                }
                grdPopup.Rebind();
     
                RadWindow1.ContentContainer.Controls.Add(grdPopup);
     
               
                rwmManager.Windows.Add(RadWindow1);
                PnlLookup.Controls.Add(rwmManager);
     
                RadAjaxManagerProxy RadAjaxManagerProxy1 = new RadAjaxManagerProxy();
                RadAjaxManagerProxy1.ID = "RadAjaxManager1";
                AjaxSetting Settings = new AjaxSetting();
                Settings.AjaxControlID = grdPopup.UniqueID;
                RadAjaxLoadingPanel RadAjaxLoadingPanel1 = new RadAjaxLoadingPanel();
                RadAjaxLoadingPanel1.ID = "RadAjaxLoadingPanel1";
     
                AjaxUpdatedControl id = new AjaxUpdatedControl();
                id.ControlID = grdPopup.ClientID;
                id.LoadingPanelID = RadAjaxLoadingPanel1.UniqueID;
     
                Settings.UpdatedControls.Add(id);
                PnlLookup.Controls.Add(RadAjaxManagerProxy1);
     
                this.Controls.Add(PnlLookup);
     
                base.CreateChildControls();
                this.ChildControlsCreated = true;
            }
  20. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    16 Dec 2010
    Link to this post
    Hi Luc Baeten,

    Can you please try adding the trigger to the update panel manually in the init event:

    void ajxPanel_Init(object sender, EventArgs e)
    {
        RadAjaxManager ajaxManager = RadAjaxManager.GetCurrent(this.Page);
        if (ajaxManager != null)
        {
            ajaxManager.AjaxSettings.AddAjaxSetting(grdItOrders, grdItOrders, ajxLoadingPanel);
            AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
            trigger.EventName = "SelectedIndexChanged";
            trigger.ControlID = GrdItOrders.UniqueID.ToString();
            grdItOrdersPanel.Triggers.Add(trigger);
     
        }
    }

    This does not seem as the entire code and markup of the control as I do not see the loading panel which throws the error.

    Greetings,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  21. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    16 Dec 2010
    Link to this post
    Hello Radoslav

    Till now I only used the RadAjaxPanel as you can see in the template ascx. But as RadAjaxpanel doesn't support trigger addition I probably have to define an UpdatePanel with the name 'grdItOrdersPanel' ??

    regards
    Luc
  22. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    16 Dec 2010
    Link to this post
    Hi Radoslav

    Without an UpdatePanel I tried this:

    void ajxPanel_Init(object sender, EventArgs e)
    {
        RadAjaxManager ajaxManager = RadAjaxManager.GetCurrent(this.Page);
        if (ajaxManager != null)
        {
            ajxPanel.AjaxSettingCreating += new RadAjaxControl.AjaxSettingCreatingDelegate(ajxPanel_AjaxSettingCreating);
            ajaxManager.AjaxSettings.AddAjaxSetting(grdItOrders, ajxPanel, ajxLoadingPanel);
            imgLoadingPanel.ImageUrl = this.Page.ClientScript.GetWebResourceUrl(this.GetType(), "GBdealer.WebControls.Resources.loading.gif");
        }
    }
    protected void ajxPanel_AjaxSettingCreating(object sender, Telerik.Web.UI.AjaxSettingCreatingEventArgs e)
    {
        AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
        trigger.EventName = "SelectedIndexChanged";
        trigger.ControlID = grdItOrders.UniqueID.ToString();
        e.UpdatePanel.Triggers.Add(trigger);
    }

    However still the same error, only another UpdatePanel name:

    A control with ID 'grdItOrders' could not be found for the trigger in UpdatePanel 'ajxPanelPanel'.



    regards
    Luc
Register for webinar
22 posts, 0 answered