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

Dynamic creation of notification

11 Answers 392 Views
Notification
This is a migrated thread and some comments may be shown as answers.
Meera
Top achievements
Rank 1
Meera asked on 26 Aug 2014, 05:48 PM
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

11 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 27 Aug 2014, 09:16 AM

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.

 
0
Meera
Top achievements
Rank 1
answered on 28 Aug 2014, 12:35 PM
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
0
Marin Bratanov
Telerik team
answered on 29 Aug 2014, 10:08 AM

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.

 
0
Meera
Top achievements
Rank 1
answered on 29 Aug 2014, 12:37 PM
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
0
Marin Bratanov
Telerik team
answered on 29 Aug 2014, 01:58 PM

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.

 
0
Sean
Top achievements
Rank 1
answered on 21 Jun 2018, 03:18 PM

Is there a way to do exactly that BUT without place holder. 

I am trying to have a utility which will take is parameters for RadNotification like title, text and stuff including Page. Goal is to have something static so that from anywhere in application i can just say RadNotificationUtility.ShowRadNotification(title, message, this.Page); and it shows me the notification.

something like this:
public static void ShowRadNotification(string title, string message, Page pageToDisplayItOn){
     RadNotification radNotice = (RadNotification)(sender.FindControl("DynamicallyCreatedRadNotification"));

     if(radNotice == null){
          radNotice = new RadNotification();

          radNotice.ID = "DynamicallyCreatedRadNotification";

         pageToDisplayItOn.Controls.Add(radNotice);

      }

      //set other attributes of radNotice here....

     string functionCall = "var dynNotice = $find('<%= DynamicallyCreatedRadNotification.ClientID %>');"

      + "if(notification != null){notification.show();} window.alert(\"i am here\");"

 

ScriptManager.RegisterClientScriptBlock(pageToDisplayItOn, pageToDisplayItOn.GetType(), Guid.NewGuid().ToString(), functionCall, true);

}

At this point i can see the alert i added of "I am here" but i do not see the notification.. 

0
Marin Bratanov
Telerik team
answered on 22 Jun 2018, 03:04 PM
Hello Sean,

It seems that the JS code is executed too early, before the notification client-side object was created, so $find() returns null. You need to use the Sys.Application.Load event for that:

I can also suggest that you consider using the built-in server-side .Show() method of the notification. You can see how its two overloads work in the following demo: https://demos.telerik.com/aspnet-ajax/notification/examples/servershowwithnewtext/defaultcs.aspx.


Regards,
Marin Bratanov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Sean
Top achievements
Rank 1
answered on 22 Jun 2018, 08:14 PM

Thank you for fast reply and your time, i highly appreciate it. 

I tried sys.application.load , .Show on server side,   .show on client side.. 

Main problem that i THINK i am having is $find giving back null if not ran that initial page load because i tried (just for debugging and experimental purpose) to add <telerik:RadNotification ..... /> in my .ascx file., so dynamically adding seems to be like not the problem however $find NOT finding it seems like the problem.. in debug mode i can see controls of the page update to include radNotification but $find either never finds and returns it or query just doesnt get executed.  

 

additional information if it helps.. on .ascx autoeventwireup = false;

button being clicked is like this:  asp:button ID="xyz" text="abc" runat=server onClick="doOnClick" UseSubmitBehavior="false"

tooltip="some info"

0
Marin Bratanov
Telerik team
answered on 25 Jun 2018, 11:52 AM
Hello,

You should remove the markup code blocks as they are resolved only when the script is rendered from the server. You should use something like string.Format() to put the ClientID in the script. For example:

string functionCall = string.Format("var dynNotice = $find('{0}');", DynamicallyCreatedRadNotification.ClientID);


Regards,
Marin Bratanov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Sean
Top achievements
Rank 1
answered on 27 Jun 2018, 01:31 PM

hello Marin,

I tried your suggestions and more but it just doesnt seem to work.. moreover, "RadNotification radNotice = (RadNotification)(pageToDisplayItOn.FindControl("DynamicallyCreatedRadNotification"));" doesnt return me anything even if i RadNotification or anything in html of that page. I did test that radNotice is being added by setting visibleOnPageLoad = true and making it crash in JS (regular postback doesnt work). I created a trial project but i cannot attach zip files so i am attaching screenshot of two simple files. At this point i am not sure what i am missing or doing wrong. 

0
Marin Bratanov
Telerik team
answered on 28 Jun 2018, 08:18 AM
Hello Sean,

Screenshots are notoriously hard to debug so I would encourage you to open a support ticket and send us the relevant files.

In the meantime, you can also look into the following:

  • having a RadNotification in the master page markup will make it very easy to call its .Show(newText) method from any content page or user control. Thus, this may make it much easier for you
  • I am not sure what goes wrong with a full postback, but if that does not work, partial postback will not work either. As a general rule of thumb, make sure you re-create the notification control with each postback, preferably in the Page_Init event, like with any other dynamically created control.
  • Place the script manager before any script controls that need it, having it as the first control in the <form> is usually the safest approach.

 


Regards,
Marin Bratanov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Notification
Asked by
Meera
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Meera
Top achievements
Rank 1
Sean
Top achievements
Rank 1
Share this question
or