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

OnResponseEnd inside of a user control

3 Answers 49 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Randy
Top achievements
Rank 1
Randy asked on 09 Sep 2008, 12:48 PM
I've read a few posts from people asking a similar question but I didn't come across a clear answer.   We are using the latest version (2008.2.723.35) and need to know the best way to get access to the OnResponseEnd inside of a usercontrol.  I realize that we can access the RadAjaxManager on the parent page. The problem with this is that that now means that my control is not fully self contained.  I need access to these events inside of the control or I need to understand what Telerik recommends here.  

Just so you know, here is what I am trying to do... Perhaps there is a better way than what I am doing. 

I have a user control that contains a button and a grid.  when the button is pressed I want to make an ajax call so I can retrieve some values from the grid (server side), do some DB updates, update a field on the page, and then (after the ajax call is complete) finally do some more javascript.   It seems like I need to tap into the OnResponseEnd in order to make sure the Ajax call is complete (and the field/variabile is updated) before I continue.

How best to approach this?

Thanks,

3 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 10 Sep 2008, 03:27 PM
Hello Randy,

I would suggest you to use the following implementation for your case:

protected void Page_Init(object sender, EventArgs e)  
{  
    RadAjaxManager manager = RadAjaxManager.GetCurrent(Page);  
    if (manager != null)  
    {  
        manager.ClientEvents.OnResponseEnd = "ResponseEnd";  
    }  
    else 
    {  
        manager = new RadAjaxManager();  
        manager.ID = "RadAjaxManager1";  
        manager.ClientEvents.OnResponseEnd = "ResponseEnd";  
        this.Page.Form.Controls.Add(manager);  
    }  

Thus your user control functionality will not depend on the existence of RadAjaxManager in the parent page.

Give it a try and let us know if this helps.

Greetings,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Randy
Top achievements
Rank 1
answered on 10 Sep 2008, 03:48 PM
That would work but...wouldn't that just replace the behavior of the parent RadAjaxManager that is on the page?  What would happen if the parent page already had an event handler for this?   I just short circuited what they were trying to do just because the page happens to have my control. 

Am I off base?
0
Iana Tsolova
Telerik team
answered on 11 Sep 2008, 09:12 AM
Hello Randy,

Indeed, this is not replacing the behavior of the main page RadAjaxManager. This way you just ensure that RadAjaxManager is available on the page and you can use it for your purpose in the user control.
However, if on the main page there is ajax manager and the OnResponseEnd client event is implemented there, you cannot be sure the your OnResponseEnd event handler will be executed. To overcome this case, you can use the ResponseScipts property of RadAjaxManager and call the additional javascript from there instead.

I hope this helps.

Best wishes,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Ajax
Asked by
Randy
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Randy
Top achievements
Rank 1
Share this question
or