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

set_text not working all the time

4 Answers 158 Views
Notification
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 15 Nov 2013, 09:15 PM
I use a button click event to show RadNotification and start the auto updates. On hide event I stop the auto updates.
I have the default text configured, and I also reset it again to the same value in button click event, before starting auto updates and calling show().
The interval is 3 seconds, so I expect the text "Retreiving PIN number" to be displayed until the first auto update occurs, yet that does not work always. The firs time I load the page and the notification shows up, it is always empty. After that, only on occasion does the default text show up. Most of the times it shows the text from the last auto update. What may be the cause.

<telerik:RadButton ID="ButtonPairAndroid" runat="server"
                Text="Pair Android Device" Width="230px" OnClick="ButtonPairAndroid_Click" OnClientClicking="CallClientShow" CausesValidation="False" />
            <telerik:RadNotification ID="RadNotification1" runat="server" Height="110px" Position="Center" Text="Retreiving PIN number" Title="Device Pairing" Width="350px" AutoCloseDelay="0" OnCallbackUpdate="OnCallbackUpdate" UpdateInterval="0" LoadContentOn="TimeInterval" OnClientHidden="OnClientHidden">
            </telerik:RadNotification>
            <telerik:RadScriptBlock ID="block" runat="server">
                <script type="text/javascript">
                    function CallClientShow(sender, args) {
                        var notification = $find("<%=RadNotification1.ClientID %>");
                        notification.set_updateInterval(3000);
                        notification.set_text("Retreiving PIN number");
                        notification.show();
                        args.set_cancel(false);
  
                    }
 
                    function OnClientHidden(sender, eventArgs) {
                        var notification = $find("<%=RadNotification1.ClientID %>");
                        notification.set_updateInterval(0);
                    }
                </script>
            </telerik:RadScriptBlock>

4 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 19 Nov 2013, 11:14 AM
Hello Alex,

Please examine this page on the basics of the control: http://www.telerik.com/help/aspnet-ajax/notification-server-side-overview.html. The key points of interest:
- the control is designed to update automatically, i.e., set new text with each update. Thus, text set with JavaScript will be reset when an update is received.
- set_text() requries a place to set the text to. Since the notification has not loaded content yet (automatic updates are disabled by default) there is no text element, because it is expected to come from the server.
- if the postback includes the notification control the text set with JavaSCript will be lost.
- you can consider the server Show(newText) method to show new content if that fits your scenario: http://demos.telerik.com/aspnet-ajax/notification/examples/servershowwithnewtext/defaultcs.aspx.
- the client-sside click of the button will be executed before the server-side event, so once the postback response is received the notification properties will be updated from the server.

So, here is the code that lets you set text in the control and make it update on interval:
<asp:UpdatePanel runat="server">
    <ContentTemplate>
        <telerik:RadButton ID="ButtonPairAndroid" runat="server"
            Text="Pair Android Device" Width="230px" OnClick="ButtonPairAndroid_Click"
            OnClientClicking="CallClientShow" CausesValidation="False" />
    </ContentTemplate>
</asp:UpdatePanel>
<telerik:RadNotification ID="RadNotification1" runat="server" Height="110px"
    Position="Center" Text="Retreiving PIN number" Title="Device Pairing"
    Width="350px" AutoCloseDelay="0" OnCallbackUpdate="RadNotification1_CallbackUpdate"
    UpdateInterval="0" LoadContentOn="PageLoad" OnClientHidden="OnClientHidden">
</telerik:RadNotification>

function CallClientShow(sender, args) {
    var notification = $find("<%=RadNotification1.ClientID %>");
    notification.set_loadContentOn(Telerik.Web.UI.NotificationLoad.TimeInterval);
    //must be set after/when LoadContentOn is TimeInterval, because it does not have sense in other contexts
    notification.set_updateInterval(3000);
    notification.show();
    notification.set_text("Retrieving PIN number");
    args.set_cancel(false);
}
 
function OnClientHidden(sender, eventArgs) {
    var notification = $find("<%=RadNotification1.ClientID %>");
    notification.set_updateInterval(0);
}

and here is the code-behind I used:
protected void RadNotification1_CallbackUpdate(object sender, RadNotificationEventArgs e)
{
    (sender as RadNotification).Text = DateTime.Now.ToString();
}
protected void ButtonPairAndroid_Click(object sender, EventArgs e)
{
 
}

You can find a short video attached.

Regards,
Marin Bratanov
Telerik
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 the blog feed now.
0
Alex
Top achievements
Rank 1
answered on 22 Nov 2013, 05:43 PM
Thanks Marin for the reply.

The changes you suggested did solve the initial appearance of the text "Retreiving PIN number"

However, the second part of the problem remains.
If the alert is closed, OnClientHidden is executed and the auto updates are stopped.
If the button is clicked again, with no page reload, and CallClientShow is executed, the text is not set to "Retreiving PIN number".
Rather, instead of it displays whatever was the last auto update content, until the new update arrives and is displayed.

0
Marin Bratanov
Telerik team
answered on 26 Nov 2013, 11:36 AM
Hello Alex,

When content is received in the notification via callbacks, it is different than the simple text property. What happens is that the text still remains "retrieving pin number", so you cannot set it again, but there is new content that overrides this. Said in code, there is such a check before setting the text in the actual markup of the control:
if(notification.get_text() != newTextValue && ...) { /* set the new text */ }

What you can do is to reset the text property of the notification, so setting it again to your desired string will show the control that you are actually changing the string, so this should have priority:
function OnClientHidden(sender, eventArgs) {
    var notification = $find("<%=RadNotification1.ClientID %>");
    notification.set_updateInterval(0);
    notification.set_text("");
}



Regards,
Marin Bratanov
Telerik
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 the blog feed now.
0
Alex
Top achievements
Rank 1
answered on 26 Nov 2013, 05:23 PM
Thanks Marin,
that worked.

I have tried setting the text to "Retreiving the PIN" in OnClientHidden, and that did not work, but I have not thought about setting it to an empty string.
Tags
Notification
Asked by
Alex
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Alex
Top achievements
Rank 1
Share this question
or