client Events in AjaxManagerProxy

23 posts, 0 answers
  1. Menno
    Menno avatar
    8 posts
    Member since:
    Jan 2006

    Posted 05 Jun 2007 Link to this post

    Hi All,

    As I'm used to setting up my ajaxification (this should be a new dictionary word :) ) in code-behind due to complex (nested)master pages I am not yet convinced the new AjaxManagerProxy saves me much development time.

    One feature that is lacking in my opinion is the ClientEvents property of the AjaxManager control.

    I need to call client events onresponseend and now I need to set this in code behind on a reference of my ajaxmanager which is located in my master page.

    Any way to do this declarative?

    Cheers,
    Olav
  2. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 06 Jun 2007 Link to this post

    Hi Mike,

    Currently you can use RadAjaxManager client events instead. I personally like the idea and will forward your request to our developers.

    Thank you for your feedback! Your Telerik points are updated for this feature request.

    If anyone else needs this feature as well, please feel free to post in this thread.

    All the best,
    Konstantin Petkov
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Shaun Peet
    Shaun Peet avatar
    571 posts
    Member since:
    Aug 2004

    Posted 07 Jun 2007 Link to this post

    I'd like to see the server-side AjaxRequest event for the proxy as well.
  5. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 07 Jun 2007 Link to this post

    Thank you for your vote, Shaun. We will definitely have it in mind.

    Best wishes,
    Konstantin Petkov
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. Pierre
    Pierre avatar
    212 posts
    Member since:
    Apr 2007

    Posted 11 Jun 2007 Link to this post

    I approuved Shaun
    I'd like to see the server-side AjaxRequest event for the proxy as well.

    it quite complicated to call the ajaxmanager from my dynamically loaded user control... ;-)

    IN my user control I try to raise the AjaxRequest without success like this:

    function EffaceMenuNodeCallBackFn(arg)
    {
       
    if(arg == "true")
        window[document.getElementById(
    'MasterRadAjaxManager').ClientID].AjaxRequest("SUPPRESSMENUNODE|");

    }

    i think I make some mistake, can you point me how? Thanks

  7. Chris Gillies
    Chris Gillies avatar
    384 posts
    Member since:
    May 2006

    Posted 12 Jun 2007 Link to this post

    the syntax you have used is not really necessary. If the control in this case the manager has a client object you can get it with window['MasterRadAjaxManager']. By default IE will try this and if not client object exists, it will try document.getElementByID ... This does not apply for Firefox and more standardized browsers.
    If you are trying to get a hold of the client dom element then you need to use
    document.getElementById("<%= MasterRadAjaxManager.ClientID %>")
  8. Pierre
    Pierre avatar
    212 posts
    Member since:
    Apr 2007

    Posted 14 Jun 2007 Link to this post

    My javascrip function are located in the user control and the MasterRadAjaxManager is located in the default.aspx page that load the usercontrol dinamically. I can't use <%= MasterRadAjaxManager.ClientID %> because the  are not defined. Maybe I will use findcontrol or define a local variable that point on the in the default page.

    For now this working good, but it work only in IE7?

    window['MasterRadAjaxManager'].AjaxRequest("SUPPRESSMENUNODE|");

  9. MB
    MB avatar
    149 posts
    Member since:
    Jan 2005

    Posted 11 Jul 2007 Link to this post

    I'd also like to vote in agreement with Shaun on the Server-Side events for the Proxy. I'm trying to grapple with this right now, where I have multiple UserControls that might be ajaxified, and 4 nested masterpages.
  10. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 11 Jul 2007 Link to this post

    Hi guys,

    You can use RadAjaxManager in any context. Here are a few examples:
    ...
    <%= RadAjaxManager.GetCurrent(Page).ClientID %>
    ...

    RadAjaxManager.GetCurrent(Page).AjaxRequest += ...

    ...

    <%= RadAjaxManager.GetCurrent(Page).ClientID %>.AjaxRequest()
    ...


    Greetings,
    Vlad
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  11. Roy Gelerman
    Roy Gelerman avatar
    12 posts
    Member since:
    Jul 2006

    Posted 11 Jul 2007 Link to this post

    We put this on our master page so we can trigger it from any content page:

    function AjaxRequestPrometheus(arg)
    { <%=AjaxManager1.ClientID%>.AjaxRequest(arg); }

    However, we're not finding the setting for the server-side function that will be called.  On the old RadAjaxManager it was

    OnAjaxRequest="myfunc". 
    Where did that property go???? Thanks,
    Roy/Dave

  12. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 12 Jul 2007 Link to this post

    Hi guys,

    You can use RadAjaxManager.GetCurrent(Page) method to find the manager - the proxy control is just helper for INamingContainers. Here is an example how attach AjaxRequest event:

    RadAjaxManager.GetCurrent(Page).AjaxRequest += ...

    Sincerely yours,
    Vlad
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  13. Roy Gelerman
    Roy Gelerman avatar
    12 posts
    Member since:
    Jul 2006

    Posted 12 Jul 2007 Link to this post

    Thanks Vlad. Is there a working example website?
  14. Shaun Peet
    Shaun Peet avatar
    571 posts
    Member since:
    Aug 2004

    Posted 13 Jul 2007 Link to this post

    I'd like to see that too...preferably in VB.
  15. MB
    MB avatar
    149 posts
    Member since:
    Jan 2005

    Posted 13 Jul 2007 Link to this post

    Agreed... a working example (C# for me) of server-side events for the Page/UserControl using the AjaxManagerProxy, would be great... as personally, I am having a bit of trouble visualising this.
  16. Larkin Young
    Larkin Young avatar
    141 posts
    Member since:
    Feb 2005

    Posted 16 Jul 2007 Link to this post

    Excellent--you guys beat me to this. I was just about to post a feature request for exposing the AjaxRequest and client-side events that are available with the RadAjaxManager from the RadAjaxManagerProxy as well. I think this would be an incredibly useful feature.

    Thanks,
    Larkin
  17. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 16 Jul 2007 Link to this post

    Hi guys,

    I have created for you a demo application which demonstrates how to use RadAjaxManager.GetCurrent(Page) method to assign client-side events for the manager when the manager is not in the same INamingContainer.

    You can find the sample web site clipped to this forum post.

    Best,
    Vlad
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  18. Shaun Peet
    Shaun Peet avatar
    571 posts
    Member since:
    Aug 2004

    Posted 16 Jul 2007 Link to this post

    Hello Vlad,

    I must apologize because this thread is now talking about two different issues.  I don't think that the difficult part was using the client-side events of the proxy and that's not what the people who wanted a sample project were looking for.

    The Server-Side AjaxRequest Event available from the proxy is what we were looking for.  For example. say you have a gridview which opens a details form with a double-click.  Upon saving the form, a client-side script from the window triggers the AjaxRequest event for the proxy which you can then access in the server-side code to do something, such as update the gridview.

    I had a whole bunch of pages that used the server-side AjaxRequest event of the old RadAjaxManager when my windows needed to do more than just update a grid.  I moved to the new version and since this server-side event wasn't available using the proxy I had to do it another way; namely using a regular asp:hiddenfield valueChanged event to run the server-side code and then using client script to change the hiddenfield's value.

    The old way of doing it was so much more slick, so that's why we really need to have the sever-side Ajax Request event exposed for the proxy.  Thanks,

    Shaun.
  19. MB
    MB avatar
    149 posts
    Member since:
    Jan 2005

    Posted 16 Jul 2007 Link to this post

    Yes, as Shuan says, we have 2 conversations going on here (the obvious short-coming of non-threaded forum posts) and it's the SERVER side events for AjaxManagerProxy that I'm interested in.

    I have a project consisting of 4 nested Masterpages, and multiple (and nested) UserControls on the page, all of which can potentially trigger Ajax Callbacks, and for which I may want to check the Ajax Values in the Ajax Event (e.g. AjaxRequest, ResolveUpdatedControls, etc).

    I'm having a lot of trouble getting my head around how to do this with the AjaxManagerProxy, as there seems to be no equivilent Ajax event support as was in the previous AjaxManager.

    If there is, then a example would be invaluable, as I can't seem to work it out.
  20. Larkin Young
    Larkin Young avatar
    141 posts
    Member since:
    Feb 2005

    Posted 16 Jul 2007 Link to this post

    I personally tried this method (I am using the MasterPage/ContentPage technique):

    //in the page_load
    RadAjaxManager ajaxManager = RadAjaxManager.GetCurrent(Page);
    ajaxManager += new RequestControl.AjaxRequestDelegate(AjaxManager_AjaxRequest);

    However RadAjaxManager.GetCurrent(Page) always returns null. Any ideas?

    - Larkin

  21. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 17 Jul 2007 Link to this post

    Hello guys,

    You can attach easily the AjaxRequest event of the manager inside the PageInit/PageLoad handler of the content page as follows:

     
        Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
            Dim manager As RadAjaxManager = RadAjaxManager.GetCurrent(Me.Page)  
            AddHandler manager.AjaxRequest, AddressOf manager_AjaxRequest  
        End Sub 

    An updated version of the project is clipped to this forum post for further reference.

    Kind regards,
    Stephen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  22. rh
    rh avatar
    193 posts
    Member since:
    Jan 2007

    Posted 09 Feb 2008 Link to this post

    I've had issues wiring up the AjaxRequest event in the Page Init method so I would recommend only doing it in the Page Load event. GetCurrent seems to return null in the Page Init event.

    As far as having multiple usercontrols registering to handle the AjaxRequest event I have come up with what I think is fair to say a rudimentary solution for supporting this. It's probably not the best solution but it works.

    First, I have an enum that identifies the different ajax request action types. For example:

    public enum AjaxRequestActionType  
    {  
        Unknown = 0,  
     
        ContactSearchSelection = 100,  
        EscrowSearchSelection = 101,  
        RequestingPersonSearchSelection = 102,  
        AddNewImageTag = 103,  
        UploadImage = 104 

    I then have a class for parsing the arguments I pass back from the ajax request:

    /// <summary> 
        /// Class used for parsing the arguments of an ajax request and determining the type of request  
        ///   
        /// The ajax request args data should be in a pipe delimited format where the first arg is the request type.  
        /// </summary> 
        public class AjaxRequestAction  
        {  
            private string _args;  
            private string _argsData; // the args without the action  
            private AjaxRequestActionType _ajaxRequestActionType;  
     
            public AjaxRequestAction(string args)  
            {  
                ParseArgs(args);  
            }  
     
            /// <summary> 
            /// The original args that were passed into the constructor  
            /// </summary> 
            public string Args  
            {  
                get { return _args; }  
            }  
     
            public string ArgsData  
            {  
                get { return _argsData; }  
            }  
     
            public string[] GetArgsDataArray()  
            {  
                string[] data = null;  
                if (!String.IsNullOrEmpty(_argsData))  
                {  
                    data = _argsData.Split('|');  
                }  
                return data;  
            }  
     
            public AjaxRequestActionType AjaxRequestActionType  
            {  
                get { return _ajaxRequestActionType; }  
            }         
     
            private void ParseArgs(string args)  
            {  
                _args = args;  
                _argsData = String.Empty;  
                _ajaxRequestActionType = AjaxRequestActionType.Unknown;  
     
                if (!String.IsNullOrEmpty(args))  
                {  
                    string[] argsargsArray = args.Split('|');  
                                      
                    if (argsArray != null && argsArray.Length > 0)  
                    {  
                        // make sure the first arg is an integer and, if so, try to map it to an AjaxRequestActionType  
                        string actionType = argsArray[0];  
                        int actionTypeNum;  
                        bool isNumeric = Int32.TryParse(actionType, out actionTypeNum);  
     
                        if (isNumeric)  
                        {  
                            if (Enum.IsDefined(AjaxRequestActionType.GetType(), actionTypeNum))  
                            {  
                                _ajaxRequestActionType = (AjaxRequestActionType)actionTypeNum;  
                            }  
                        }  
     
                        if (argsArray.Length > 1)  
                        {  
                            // there are additional args so copy the args data starting after the ajaxt request type which  
                            // is at position zero  
                            //string[] argsDataArray = new string[argsArray.Length - 1];  
                            //argsArray.CopyTo(argsDataArray, 1);  
                            _argsData = SplitJoin.Join<string>(argsArray, "|", 1);  
                        }  
                    }  
                }  
            }  
        } 

    Then in my javascript in my usercontrol I do the following. Most of my manual ajax requests are the result of an action in a RadWindow which this function is an example of. What I do here is build a pipe delimted argument string where the first value is the ajax action.

    function UploadImageCallback_<%= this.ClientID %>(radWindow, returnValue)  
        {  
            //alert('in upload image callback: ' + returnValue);  
            if (!isNaN(returnValue))  
            {  
                //alert('ImageViewer callback called');                   
                var ajaxManager = <%= Telerik.Web.UI.RadAjaxManager.GetCurrent(Page).ClientID %>;         
                  
                var requestActionType = '<%= Convert.ToInt32(IMS.Shell.AjaxRequestActionType.UploadImage) %>';  
                var thisClientID = '<%= this.ClientID %>';  
                var returnValueWithRequestType = requestActionType + '|' + thisClientID + '|' + returnValue;  
                //alert('returnValueWithRequestType = ' + returnValueWithRequestType);  
                // this initiates an asynchronous call to the server to populate the contact data  
                ajaxManager.AjaxRequest(returnValueWithRequestType);  
            }  
        } 

    Then on the server side I pass the arguments to my AjaxRequestAction class so it can parse the arguments. I can then check the AjaxRequestActionType to see if my particular usercontrol should be handling this ajax request. This way if I have multiple usercontrols on a page registered to handle ajax requests my other usercontrols can ignore the request and only the appropriate one will handle it. I typically even pass the usercontrol ClientID as the second argument and check that just in case I have multiple instances of the same usercontrol on a page.

    protected void ajaxManager_AjaxRequest(object sender, AjaxRequestEventArgs e)  
        {  
            AjaxRequestAction ajaxAction = new AjaxRequestAction(e.Argument);  
            if (ajaxAction.AjaxRequestActionType != AjaxRequestActionType.UploadImage)  
            {  
                // the ajax request was not triggered by a upload image action so don't act on it  
                return;  
            }  
              
            string returnValueWithClientID = ajaxAction.ArgsData;  
            string[] args = returnValueWithClientID.Split('|');  
     
            if (args.Length > 1)  
            {  
                string clientID = args[0];  
                string imageRefIDStr = args[1];  
     
                int imageRefID;  
                bool parsed = Int32.TryParse(imageRefIDStr, out imageRefID);  
                if (parsed)  
                {  
                    OnNeedImages(new EventArgs());  
                    LoadByImageRefID(imageRefID);  
                }  
            }  
        } 

    Like I say, it's probably not the best solution but it works and once you get it set up it's a pretty easy pattern to follow.
  23. Daron
    Daron avatar
    80 posts
    Member since:
    Dec 2007

    Posted 11 Feb 2008 Link to this post

    Wow! Isn't buying 3rd party controls supposed to make our lives easier and not more difficult?

    I think with the amount of "hacking together" that rh has done it would have been easier to write his/her own ajax framework!

    RadAjaxProxyManager needs an AjaxRequest  event (without it it's pointless) and AjaxRequest needs an extra argument (being the "initiating" control) so that we can use the one method for several ajax calls and handle the code according to who fired it.

    For now I'm also using the RadAjaxManager delegate approach.

    Cheers
  24. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 11 Feb 2008 Link to this post

    Hi Daron,

    We have not exposed AjaxRequest event for the RadAjaxManagerProxy because it is pretty straight-forward to get access to the RadAjaxManager on the main page/master page with the GetCurrent(Page) method and attach the manager's AjaxRequest event. Let me know whether you come upon some obstacles with the solution posted in my previous reply (inside the PageLoad handler).

    Best regards,
    Stephen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017