Dynamic creation of notification

6 posts, 0 answers
  1. Meera
    Meera avatar
    14 posts
    Member since:
    Mar 2012

    Posted 26 Aug 2014 Link to this post

    I am trying to create dynamic notifications based on the database content. As a simplified version of what i have, for the following database table : 

    ID        Notification         NotificationText              NotificationTimeInterval
    1          FillLog                   Fill the time log                   9000
    2          CheckMesg          Check the message            500
    3          Print                       Print report                         3000


    Each notifications need to appear based on this table at the specified NotificationTimeInterval and the notifications should be created programatically since the number of records in the table itself is varying.  Can someone point me to the right direction or with a sample project on how to accomplish this?

    Thanks,
    Meera
  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3602 posts

    Posted 27 Aug 2014 Link to this post

    Hi Meera,

    You can create the controls programmatically according to your data. Here is a really simple example:

    protected void Page_Init(object sender, EventArgs e)
    {
        var data = GetData();//get your actual data and loop through it
        for (int i = 0; i < data.Rows.Count; i++)
        {
            CreateNotification(data.Rows[i]["Notification"].ToString(), data.Rows[i]["NotificationText"].ToString(), Int32.Parse(data.Rows[i]["NotificationTimeInterval"].ToString()), Placeholder1);
        }
    }
     
    protected void CreateNotification(string id, string text, int interval, PlaceHolder container)
    {
        RadNotification rn = new RadNotification();
        rn.ID = id;
        rn.ShowInterval = interval;
        rn.Text = text;
        rn.KeepOnMouseOver = false;
        rn.Width = Unit.Pixel(300);
        rn.Height = Unit.Pixel(200);
        if (id == "CheckMesg")
        {
            rn.Position = NotificationPosition.BottomCenter;
        }
        else
        {
            rn.Position = NotificationPosition.Center;
        }
        //set other properties as needed
        container.Controls.Add(rn);
    }
     
     
    protected DataTable GetData()
    {
        DataTable tbl = new DataTable();
        tbl.Columns.Add(new DataColumn("Notification"));
        tbl.Columns.Add(new DataColumn("NotificationText"));
        tbl.Columns.Add(new DataColumn("NotificationTimeInterval"));
        tbl.Rows.Add(new object[] { "FillLog", "Fill the time log", 9000 });
        tbl.Rows.Add(new object[] { "CheckMesg", "Check the message", 500 });
        tbl.Rows.Add(new object[] { "Print", " Print report", 3000 });
        return tbl;
    }

    Note that the ShowInterval property and UpdateInterval properties are in milliseconds.

    Regards, Marin Bratanov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Meera
    Meera avatar
    14 posts
    Member since:
    Mar 2012

    Posted 28 Aug 2014 in reply to Marin Bratanov Link to this post

    Thank you Marin. I got this to work.

    I have another question. For ShowInterval property, instead of setting an interval, is there a way to use a time stamp directly. For example, to run the notification every day at 21:47:29.000. Or the only option i have is to convert the time into interval duration in milliseconds?

    Thanks,
    Meera
  5. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3602 posts

    Posted 29 Aug 2014 Link to this post

    Hello Meera,

    The ShowInterval takes an interval in milliseconds that is counted from the time the notification client-side object is created until it is shown, then reset and counted again. It is not possible to set an exact time of day to show it on. If you would like to see such a feature implemented, I suggest you post it in our feedback portal (http://feedback.telerik.com/Project/108/) together with a detailed description of the expected behavior and the way you would like to use it. If it becomes popular, we will consider its implementation.


    Regards,

    Marin Bratanov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. Meera
    Meera avatar
    14 posts
    Member since:
    Mar 2012

    Posted 29 Aug 2014 in reply to Marin Bratanov Link to this post

    Thank you Marin.

    As you suggested, i have posted a feature request in the portal (http://feedback.telerik.com/Project/108/Feedback/Details/136825-radnotification-for-a-particular-time-of-day). Meanwhile, could you suggest a workaround for this? I am assuming, if i need to run a notification for a particular time of day, the ShowInterval value will be 24 hours in milliseconds, but how can i ensure that it starts at that time?

    Thanks,
    Meera
  7. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3602 posts

    Posted 29 Aug 2014 Link to this post

    Hello Meera,

    The workaround I can suggest is to use the Value property of the control to store the desired time (e.g., 09:00). ON the client, in the Sys.Application.Load event, get a reference to the control, get the current time and calculate their difference in milliseconds. This would be the time that needs to pass between the time the control initializes and the time it has to show up. Then, set it to the ShowInterval property via the client-side API of the control.


    Regards,

    Marin Bratanov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017