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

Setting Title and TitleIcon in OnCallbackUpdate?

3 Answers 133 Views
Notification
This is a migrated thread and some comments may be shown as answers.
SteveV
Top achievements
Rank 1
SteveV asked on 09 Dec 2011, 07:17 PM
Hi,

I'm displaying a RadNotification control from within an async postback.  The markup for the RadNotification looks like this:

<telerik:RadNotification ID="AddToCartNotification" runat="server" Animation="Fade" AutoCloseDelay="5000" ContentIcon="" Height="100px" Opacity="80" Position="Center" Skin="Forest" Width="300px" EnableRoundedCorners="True" EnableShadow="True" LoadContentOn="EveryShow" oncallbackupdate="AddToCartNotification_CallbackUpdate" Title="Add to Cart Result" />

My code behind looks like this:
protected void OnVideoRepeaterItemCommand(object source, RepeaterCommandEventArgs e)
{
    switch (e.CommandName)
    {
        case "AddToCart":
            {
                AddItemToCart((string)e.CommandArgument);
                break;
            }
    }
}
 
private void AddItemToCart(string productSku)
{
    ShoppingCartUtilities.AddToCartResult result = ShoppingCartUtilities.AddItemToCart(productSku, 1, 1);
    string caption = "";
    string msg = "";
    string icon = "";
 
    if (result == ShoppingCartUtilities.AddToCartResult.ItemAddSucceeded)
    {
        icon = "info";
        caption = "Item Added";
        msg = "Item successfully added to cart";
    }
 
    else if (result == ShoppingCartUtilities.AddToCartResult.ItemAddFailedMaxItemCountReached)
    {
        icon = "warning";
        caption = "Maximum Count for Item Reached";
        msg = "Only one copy of this video can be added to your cart";
    }
 
    else
    {
        icon = "deny";
        caption = "Unable to Add Item to Cart";
        msg = "Add to cart failed.  Sorry for the inconvenience";
    }
 
    string value = string.Format("{0}|{1}|{2}", icon, caption, msg);
    AddToCartNotification.Value = value;
             
    AddToCartNotification.Show();
}
 
protected void AddToCartNotification_CallbackUpdate(object sender, Telerik.Web.UI.RadNotificationEventArgs e)
{
    RadNotification notification = sender as RadNotification;
  
    if(notification == null)
        return;
 
    string[] vals = notification.Value.Split('|');
 
    if (vals == null || vals.Length < 3)
        return;
 
    AddToCartNotification.TitleIcon = vals[0];
    AddToCartNotification.Title = vals[1];
    //AddToCartNotification.ContentIcon = vals[0];
    AddToCartNotification.Text = vals[2];
}

I'm able to set the Text property but not able to set the Title and TitleIcon properties.  Am I missing something or is this not possible?

Thanks -- Steve

3 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 12 Dec 2011, 09:42 AM
Hello Steve,

The OnCallbackUpdate event of the RadNotification is triggered as a callback, not an AJAX request, which means that this is the only method called (instead of the entire page lifecycle as is with an AJAX request). This means that only the contents of the panel that is being updated can be transferred back to the client and this does not include the titlebar of the notification, only its ContentTemplate (or Text). The only exception is the Value property which is also transferred, which is a special case we have considered and taken care to pass. You can find more information on the matter in this demo's description section as well (for example an alternative is using AJAX to update the entire control so that you can set properties).


Kind regards,
Marin
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
0
SteveV
Top achievements
Rank 1
answered on 12 Dec 2011, 02:45 PM
Hi Marin,

Thanks for the reply.  I've had another look at the demo page as well as the documention but I can't see any related to "using AJAX to update the entire control so that you can set properties".

Am I missing something?

Thanks--Steve
0
Marin Bratanov
Telerik team
answered on 13 Dec 2011, 04:46 PM
Hi Steve,

Using RadNotification with AJAX it not different than using any other control. Please examine the attached page for a simple example that uses RadAjaxManager as the easiest way to incorporate AJAX into your application. Please note that in this case I am not using the OnCallBack update as I can already set the needed information in the control.

If you need to do this with a timer things can become more difficult, though, especially if you wish to keep the easy functionality from the notification's built-in timer and change things outside of its content. What I would advise is that you either use the above approach (you can modify it to use an asp timer instead of a button click) or simply only change the text in the callback, as this is its intended purpose - a notification with general title that can display information based on something on the server (for example new messages or the server time, or current number of users, etc.).


Best wishes,
Marin
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
Tags
Notification
Asked by
SteveV
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
SteveV
Top achievements
Rank 1
Share this question
or