new message notification, content disappears

3 posts, 1 answers
  1. Dan
    Dan avatar
    7 posts
    Member since:
    Jun 2012

    Posted 20 Jun 2012 Link to this post

    Hello,

    I have a couple of issues with my new message notification.  First, calling the code-behind .show() method in the CallBackUpdate event does not seem to do anything.  I had to use the javascript method shown in the Notification / Update on interval demo, and that works.

    Secondly and more importantly, when the notification is displayed, normally it disappears after the AutoCloseDelay (7 secs) has elapsed.  This is fine, unless the user mouses over the notification if they want to read it longer.  The notification itself remains, but after the UpdateInterval (10 secs) elapses, the .Text value of the LinkButton control in the ContentTemplate is wiped out.  Does it not persist in the viewstate?  Not sure how to work around this.  Once the notification is shown, the data is flagged as such so that it does not show again.

    Thanks,
    Dan

    <script type="text/javascript">
    function OnClientUpdated(sender, args) {
        var newMsgs = sender.get_value();
        if (newMsgs != 0) {
            sender.show();
        }
    }
         
    </script>

    <telerik:RadNotification ID="RadNotification1" runat="server" Width="330px" Height="75px" OnClientUpdated="OnClientUpdated" ContentIcon="" TitleIcon="~/App_Themes/MainTheme/images/message_16.png" Title="New Message(s)" LoadContentOn="TimeInterval" UpdateInterval="10000" Animation="Fade" AutoCloseDelay="7000" OffsetX="-10" OffsetY="-35">
    <ContentTemplate>
    <asp:LinkButton ID="lbNotification" runat="server" PostBackUrl="~/Messages.aspx" CssClass="msg"></asp:LinkButton>
    </ContentTemplate>
    </telerik:RadNotification>

    Protected Sub RadNotification1_CallbackUpdate(sender As Object, e As Telerik.Web.UI.RadNotificationEventArgs) Handles RadNotification1.CallbackUpdate
     
        Dim MsgFrom As String = ""
        Dim Regarding As String = ""
        Dim Message As String = ""
     
        If CheckForMessages(MsgFrom, Regarding, Message) Then
            Message = Replace(Message, "<br>", " ")
            Message = IIf(Len(Message) > 60, Left(Message, 60) & "...", Message)
     
            lbNotification.Text = "<b>" & MsgFrom & "</b><br>" & _
                                  Regarding & "<br>" & _
                                  Message
            RadNotification1.Value = 1
        Else
            RadNotification1.Value = 0
        End If
     
    End Sub

  2. Answer
    Marin Bratanov
    Admin
    Marin Bratanov avatar
    3595 posts

    Posted 21 Jun 2012 Link to this post

    Hi Dan,

    The callback update mechanism relies on a webform callback and thus it is not a full or even ajax postback where you can modify many properties or inject scripts. It only includes the markup of the updated part of the page, which is, in this case, only the content of the notification, which is why we have taken special measures to pass the Value property of the notification so that it can be used to show the control depending on a certain condition, just as you have discovered.

    As for your second question - what happens is that after 10 seconds the new content arrives from the server and replaces the new content. This behavior can be changed by cancelling the OnClientUpdating event in case the notification is already shown, e.g.:
    function OnClientUpdating(sender, args)
    {
        if (sender.isVisible())
        {
            args.set_cancel(true);
        }
    }

    Note that this will mean that the new value and/or content will not reach the OnClientUpdated event and thus its logic will not be executed against them.

    What I can suggest alternatively is that you avoid automatic updates but call its update() method in the OnClientHidden event (with a 10 second timeout) in case this suits your needs better. This can be done by removing the UpdateInterval and LoadContentOn properties and by adding the following code to the pageLoad() shortcut and to the OnClientHidden event hadler:
    setTimeout(function () { $find("RadNotification1").update(); }, 10000);

    which will cause an update only if the notification hides. The OnClientUpdated event handler is still necessary and you would need to invoke the manual update() in it in case the notification does not need to show.
    if (newMsgs != 0)
    {
        sender.show();
    }
    else
    {
        setTimeout(function () { $find("RadNotification1").update(); }, 10000);
    }


    Greetings,
    Marin Bratanov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dan
    Dan avatar
    7 posts
    Member since:
    Jun 2012

    Posted 21 Jun 2012 Link to this post

    Thanks Marin!  Your first solution worked perfectly.

    Thanks,
    Dan
Back to Top