dynamic content template

4 posts, 0 answers
  1. Tia
    Tia avatar
    18 posts
    Member since:
    Mar 2013

    Posted 31 Jul 2013 Link to this post

    Hi,

    I have a radwindow in the aspx. During runtime how can I add a content template to it?

    Thanks
    Tia
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 31 Jul 2013 Link to this post

    Hi Tia,

    Please have a look into the following code I tried which works fine at my end.

    ASPX:
    <telerik:RadWindow ID="RadWindow1" runat="server" Width="350px" Height="350px">
    </telerik:RadWindow>
    <telerik:RadButton ID="RadButton2" runat="server" Text="Add Content Template"
        OnClick="RadButton2_Click">
    </telerik:RadButton>

    C#:
    protected void RadButton1_Click(object sender, EventArgs e)
    {
        RadTextBox radtextbox1 = new RadTextBox();
        radtextbox1.Text = "Sample Text";
        RadWindow1.ContentContainer.Controls.Add(radtextbox1);
        RadButton radbutton1 = new RadButton();
        radbutton1.Text = "Click";
        RadWindow1.ContentContainer.Controls.Add(radbutton1);
        RadWindow1.VisibleOnPageLoad = true;
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Stephen Rouse
    Stephen Rouse avatar
    23 posts
    Member since:
    Feb 2005

    Posted 02 Aug 2013 Link to this post

    I have a similar problem I am dynamically adding controls to a panel in the code behind, each control is a button which I have styled in the page, and want the new buttons to be similar. The code below is that being used in the web page;
    <telerik:RadButton runat="server" ID="RadButton6" Width="225" Height="40" CssClass="dialogclosebtn" RenderMode="Lightweight" Skin="MetroTouch" OnClick="CloseAddActivityRadButton_Click" ToolTip="Close this notification" Text="Test">
     
    <ContentTemplate>
     
    <span class="btnText">Close Dialog</span>
     
    </ContentTemplate>
     
     </telerik:RadButton>

    In the code behind, I have the following:
    private RadButton CreateButton(string title, string tooltip)
    {
        RadButton rbtn = new RadButton();
        rbtn.Width = 225;
        rbtn.Height = 20;
        rbtn.CssClass = "dialogclosebtn";
        rbtn.RenderMode = RenderMode.Lightweight;
        rbtn.Skin = "MetroTouch";
        rbtn.Text = title;
        rbtn.ToolTip = tooltip;
        rbtn.Click += rbtn_Click;
     
        //Template
        //rbtn.ContentTemplate =
     
        return rbtn;
    }

    I am stuck at adding the content, but also the styling is not being applied.

    Kind Regards

    Steve Rouse




  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 06 Aug 2013 Link to this post

    Hi Stephen,

    Please have a look into the following code I tried to add a RadButton ContentTemplate from C# code.

    C#:
    protected void Page_Load(object sender, EventArgs e)
    {
        RadButton6.ContentTemplate = new ButtonContentTemplate();
    }
    public class ButtonContentTemplate : ITemplate
    {
        void ITemplate.InstantiateIn(Control container)
        {
            System.Web.UI.WebControls.Image contentImage = new System.Web.UI.WebControls.Image();
            contentImage.ID = "contentImage";
            contentImage.ImageUrl = "../Images/copy.png";
            contentImage.AlternateText = "envelope";
            container.Controls.Add(contentImage);
     
            Label contentLabel = new Label();
            contentLabel.ID = "contentLabel";
            contentLabel.CssClass = "btnText";
            contentLabel.Text = "E-Mail";
            container.Controls.Add(contentLabel);
        }
    }

    Thanks,
    Princy.
Back to Top