This is a migrated thread and some comments may be shown as answers.

Creating RadNotificacion and rich content (ContentTemplate) dynamically

3 Answers 223 Views
Notification
This is a migrated thread and some comments may be shown as answers.
Nefi
Top achievements
Rank 1
Nefi asked on 24 Jul 2012, 11:21 PM
Hi everyone,

I'm having an issue trying to add rich content to a RadNotification created dynamically. I'm developing ASP.NET Composite Server Controls that nests Telerik controls and it is imposible to add any control to the RadNotification's ContentTemplate/ContentContainer. This is my code:

protected override void CreateChildControls()
{
    var _notification = new RadNotification
    {
        ID = "Notification",
        Position = NotificationPosition.Center,
        Height = Unit.Pixel(160),
        Width = Unit.Pixel(330),
        TitleIcon = "ok",
        Animation = NotificationAnimation.Slide,
        AutoCloseDelay = 0,
        ShowCloseButton = false,
    };
    var div = new HtmlGenericControl("div");
    div.Controls.Add(new LiteralControl("<br />"));
    div.Controls.Add(new Literal { Text = Resources.MyControl_TextMessage });
    div.Controls.Add(new LiteralControl("<br />"));
    div.Controls.Add(new RadButton { Text = Resources.MyControl_ButonText });
    _notification .ContentContainer.Controls.Add(div);
    this.Controls.Add(_notification);
}

BTW, this is not the full method, full method contains a lot of more controls, this is just a sample.

Hope anyone knows how can I achieve it.

Thanks,
Nefi

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 25 Jul 2012, 04:04 AM
Hi Nefi,

With reference to this documentation "If you are planning to add controls dynamically you need to declare an empty ContentTemplate, since if it is not present RadNotification automatically detects it and enters into simple content mode and you will not be able to add controls in it." Following is the sample code that I tried to add controls dynamically to RadNotification.

C#:
RadNotification _notification = new RadNotification();
protected override void OnInit(EventArgs e)
 {
   _notification.ContentTemplate = new NotificationTemplate();
   base.OnInit(e);
 }
protected void Page_Load(object sender, EventArgs e)
 {
   _notification.ID = "Notification";
   _notification.Position = NotificationPosition.Center;
   _notification.Height = Unit.Pixel(160);
   _notification.Width = Unit.Pixel(330);
   _notification.TitleIcon = "ok";
   _notification.Animation = NotificationAnimation.Slide;
   _notification.AutoCloseDelay = 0;
   _notification.ShowCloseButton = false;
   _notification.VisibleOnPageLoad = true;
   var div = new HtmlGenericControl("div");
   div.Controls.Add(new LiteralControl("<br />"));
   div.Controls.Add(new Literal { Text = "ffggh" });
   div.Controls.Add(new LiteralControl("<br />"));
   div.Controls.Add(new RadButton { Text = "tftyh" });
   _notification.ContentContainer.Controls.Add(div);
   form1.Controls.Add(_notification);
 }
 
//creating an empty ContentTemplate
 
class NotificationTemplate : ITemplate
 {
   public void InstantiateIn(Control container)
    {
    }
 }

Hope this helps.

Regards,
Princy.
0
Nefi
Top achievements
Rank 1
answered on 25 Jul 2012, 10:24 PM
Yeah, It worked like a charm!

Thank you very much,
Nefi
0
Meera
Top achievements
Rank 1
answered on 09 Oct 2014, 06:48 PM
I would like to use the above method to create Notifications but slightly different. In my case, I would like to create multiple notifications based on database records. The database records contain the notification text, interval etc and multiple notifications need to be created dynamically based on the number of records. Could you suggest a modification for the above answer to fit my criteria? 
Tags
Notification
Asked by
Nefi
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Nefi
Top achievements
Rank 1
Meera
Top achievements
Rank 1
Share this question
or