Creating RAD Controls Completely Programatically

5 posts, 0 answers
  1. S
    S avatar
    2 posts
    Member since:
    Nov 2008

    Posted 01 Dec 2008 Link to this post

    I would like to  create RAD controls programatically, without initially dragging and dropping the controls from the toolbar.  All of the documentation and information I've reviewed covers adding items and configuring the controls (progamatically) 'after' you drag a control onto the design surface initially.

    What I want to do is create an ASP.NET custom control, that creates and configures rad controls... can anyone help out?  Thought I could just do someting like:

    RadMenu menu = new RadMenu();
  2. Kevin Babcock
    Kevin Babcock avatar
    189 posts
    Member since:
    Mar 2007

    Posted 01 Dec 2008 Link to this post


    You are absolutely correct. In order to add a control programmatically all you need to do is simple instantiate that control and set any properties, then add that control to the containing control. So, if you wanted to create a new RadGrid, bind it to a List of data, and then add it to a RadAjaxPanel, you could do it like this:

    var radGrid = new RadGrid { ID = "RadGrid1" }; 
    radGrid.DataSource = new ArrayList 
        new { FirstName = "John", LastName = "Doe", Age = 27 }, 
        new { FirstName = "Frank", LastName = "Smith", Age = 39 }, 
        new { FirstName = "Sue", LastName = "Wilson", Age = 18 } 

    Keep in mind that all RadControls live inside the Telerik.Web.UI namespace. So you will have to either use the fully qualified class names when instantiating the controls, or add a using directive to your source file.

    I hope this helps. Please let me know if you have any further questions.

    Kevin Babcock
  3. S
    S avatar
    2 posts
    Member since:
    Nov 2008

    Posted 01 Dec 2008 Link to this post

    That's what I thought... although I've been working with the menu and panel bars to start... but not having much luck... for instance in trying to create a panel bar from a code-behind I have:

    RadScriptManager scriptmgr = new RadScriptManager();
    RadPanelBar panelbar = new RadPanelBar();
    RadPanelItem menuitem = new RadPanelItem();
    menuitem.Text = "Test";

    This does not render anything on the aspx page however...
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 02 Dec 2008 Link to this post


    Try creating the scriptmanager declaratively and then adding the dynamically created panelbar control to the control collection of the script manager as shown below.
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server"

            RadPanelBar panelbar = new RadPanelBar(); 
            RadPanelItem menuitem = new RadPanelItem(); 
            menuitem.Text = "Test"

    Also go through this link which explains on programmatic creation of the RadGrid control.

  5. Paul
    Paul avatar
    4281 posts

    Posted 02 Dec 2008 Link to this post

    Hi there,

    Please find below your modified code snippet that shows the needed approach.

    protected void Page_Load(object sender, EventArgs e)  
        RadScriptManager scriptmgr = new RadScriptManager();  
        scriptmgr.ID = "RadScriptManager1";  
        RadPanelBar panelbar = new RadPanelBar();  
        panelbar.ID = "RadPanelBar1";  
        if (!IsPostBack)  
            RadPanelBar pb = (RadPanelBar)Page.FindControl("RadPanelBar1");  
            RadPanelItem menuitem = new RadPanelItem();  
            menuitem.Text = "Test";  

    Best wishes,
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top