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

Generic way of displaying error message in master page while using RadAjaxManagerProxy

4 Answers 206 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Nishanth
Top achievements
Rank 1
Nishanth asked on 06 Jul 2011, 09:20 PM
Hi,

I have a master page whenere my RadAjaxManager is added and in the content pages, I have RadAjaxManagerProxy .
Now I need to display success/failure messages on the content page events like (button clicks , grid update/ combobox changed etc)  in a Label in MasterPage.
Right now I am wiring each control which can cause a failure/success message to the RadAjaxManager using the following code:
 RadAjaxManager AjaxManager = (RadAjaxManager)this.Master.FindControl("RadAjaxManager1");
        //AjaxManager.AjaxSettings.AddAjaxSetting(RadButton1, Label1);

        Label lblMessage = (Label)this.Master.FindControl("lblMessage");
        AjaxManager.AjaxSettings.AddAjaxSetting(RadButton1, lblMessage);

This code works fine. But my concern is that in future we may add more buttons/grids/combo boxes in the page. Then I need to add the above code for all controls which may not a scalable solution.  A new programmer may not know about the need to wire control as above.

So I was wondering if there is a way to do a generic wiring so that any event happening in the content page can update the label in the master page which is a common scenario.
I have a custom base class for all the pages. So a solution in the base class which will work for all the pages and future pages will be really great.
 
Any thoughts? Any help will be much appreciated. Thanks a lot..

4 Answers, 1 is accepted

Sort by
0
Genti
Telerik team
answered on 07 Jul 2011, 02:49 PM
Hello Nishanth,

Thank you for contacting us.

In this case you can make use of the AjaxManager ResponseScripts property.

I am attaching a simple solution that illustrates how you can achieve your desired functionality.

Some notes:
-In the master page I have defined the AjaxManager, the div that is going to display the message and some client side javascript function to update the div with the response that comes from the server.
function alertByAjaxManager(arg) {
    document.getElementById("divError").innerHTML = arg;
}

-In the child page I get a refence to the AjaxManager and through the response script i call the javascript function that I defined in the masterpage to update the current message.
protected void ErrorProcessClick_Handler(object sender, EventArgs e)
{
    RadAjaxManager manager = RadAjaxManager.GetCurrent(Page);
    manager.ResponseScripts.Add("alertByAjaxManager('Something from AjaxManager')");
    
}


Let me know if this helps.

Greetings,
Genti
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Nishanth
Top achievements
Rank 1
answered on 07 Jul 2011, 03:09 PM
Hi, Thanks for the reply. This is a good way of doing it, but my problem is that the control which displays the message is a user control. I assign the messages to a session and in the prerender even of the master page, this user control displays the error message. it displays the messages in a dock panel and the dock panel's color changes depending on message type (error, success etc) . The message list is a custom list . Because of this, the javascript solution wont work.

Is there a generic way to telle Telerik AjaxManager that during ajax post back, in all the content pages, this particular control will be updated? using AjaxSettings?

Thanks a lot ...
Nishanth
0
Genti
Telerik team
answered on 07 Jul 2011, 03:57 PM
Hi Nishanth,

Thank you for contacting us back.

In this case, I suppose one solution would be to add in the response script a function which is going to update the user control. For this you should specify the Ajax manager as ajax initiator and the user control as an updated control.

Even though this might be a solution I would not suggest that as it will perform an extra postback just by fetching a small chunk of message.

A better solution would be to reimplement the error message displaying entirely on Javascript. Which means that the message type and the custom list of errors needs to be translated in Javascript.

Hope this helps.

Kind regards,
Genti
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Nishanth
Top achievements
Rank 1
answered on 07 Jul 2011, 04:08 PM
Thanks a lot Genti !!
Tags
Ajax
Asked by
Nishanth
Top achievements
Rank 1
Answers by
Genti
Telerik team
Nishanth
Top achievements
Rank 1
Share this question
or