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

Attach more than one function to RadAjaxManager's OnRequestStart or OnRequestEnd

3 Answers 116 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Andrew Lawrence
Top achievements
Rank 1
Andrew Lawrence asked on 01 Dec 2010, 02:30 AM
Is there a clean, modular way to do this?

For example, the following code is dangerous because it may erase any existing function that is attached to OnRequestStart:

RadAjaxManager.GetCurrent(Page).ClientEvents.OnRequestStart = "DoSomething";

3 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 02 Dec 2010, 03:51 PM
Hello Andrew,

Could you please elaborate a bit more on your scenario and the exact functionality you need to achieve. Pasting some code from your application which represents the Ajax settings you have, could help us provide more to-the-point answer.


Best wishes,
Maria Ilieva
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Andrew Lawrence
Top achievements
Rank 1
answered on 03 Dec 2010, 03:20 AM
I have a script that needs to fire OnResponseEnd that is designed to retain focus on the active element after an AJAX postback.
This script is registered in a global manner, e.g. in a master page:

public class MasterPageBase : MasterPage
{
        protected override void OnLoad(EventArgs e)
        {
            radAjaxManager.ClientEvents.ResponseEnd = "TrackFocusAfterAjaxPostback";
            base.OnLoad(e);
        }
}


But now I have a requirement that applies to a particular content page. After an AJAX postback, I need to make sure that any controls that have become visible are processed by some javascript. For example:

<script type="text/javascript">
    function AttachEventsToTextboxes() {
        $(':text').change(function () { DoSomething(); });
    }
 
    // Attach events on load
    AttachEventsToTextboxes()
</script>


... and In the code behind:

public partial class MyContentPage : Page
{
        protected override void OnLoad(EventArgs e)
        {
            RadAjaxManager.GetCurrent(Page).ClientEvents.ResponseEnd = "AttachEventsToTextboxes";
            base.OnLoad(e);
        }
}



The problem is that the subpage's ResponseEnd script will overwrite the Master Page's ResponseEnd script.
This may not be obvious to the developer, resulting in subtle bugs.
0
Maria Ilieva
Telerik team
answered on 07 Dec 2010, 03:19 PM
Hi Andrew,

The ResponseEnd is a client event so you cannot call two functions in the same time. In your case I would suggest you to please the code used in the MasterPage function in the content page function so it will be executed in the same time.


Greetings,
Maria Ilieva
the Telerik team

Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Ajax
Asked by
Andrew Lawrence
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Andrew Lawrence
Top achievements
Rank 1
Share this question
or