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

Only single Ajax Amanager per page?

15 Answers 912 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Yuri
Top achievements
Rank 1
Yuri asked on 24 Apr 2007, 11:52 PM
It seems that only one single instance of AjaxManager is allowed per page. What happens if I create a couple of user controls that incorporate AjaxManager? Is this is a bug or intentionally designed like this?

15 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 25 Apr 2007, 07:26 AM
Hello Yuri,

The new ajax manager is designed to work in similar to ScriptManager way. You can use GetCurrent() method to get the manager from the user controls.

Kind regards,
Vlad
the telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Iurii
Top achievements
Rank 1
answered on 25 Apr 2007, 07:46 AM
That helps :)

Thank you
0
Iurii
Top achievements
Rank 1
answered on 25 Apr 2007, 05:06 PM
Thanks for the help. Everything works.  I also have noticed that i can use ajaxLoadingPanel on user controls, however in design time it is telling me that i need an instance of the scriptmanager.
0
Leon
Top achievements
Rank 1
answered on 26 Apr 2007, 06:40 AM
Ramin,

From migration steps article:

http://www.telerik.com/help/radcontrols/prometheus/ajxMigration.html

It seems that you must have the ScriptManager on each page using RadAjax Prometheus controls.

Regards,
Leon
0
Shaun Peet
Top achievements
Rank 2
answered on 26 Apr 2007, 04:17 PM
Vlad,

Can you provide a little more details about the GetCurrent() method; perhaps even a little example of how to use it.

I'm trying to wrap my head around how to acheive this particular solution with the new AjaxManager:

Master Page -> Default.aspx page.  The Default.aspx page dynamically loads user controls.  In one such case a single page contains two user controls in a shopping-cart type situation - where one user control displays products and the other user control shows the number of items in the cart.

Using the old radAjax I would have an AjaxManager in each user contol.  The user control that displayed the products would use a callback to add the item to the cart, and then call some javascript within the cart user control that would trigger an AjaxManager.AjaxRequest() to update the number of items in the cart:

<script language="javascript" type="text/javascript">  
 
    function clientCartUpdate()  
    {  
        var AjaxManager = <%= ramCartItmes.ClientID %>;  
        AjaxManager.AjaxRequest('UpdateItems');  
    }  
      
</script> 


Now, using the new r.a.d.Ajax I've plopped the AjaxManager and ScriptManager on the master page.  This means that I can't reference the AjaxManager using that same javascript function because it references the server-side AjaxManager that no longer exists within the user control.  So, in theory, I suppose I could move both the server-side code and client-side code to the master page; but that creates unneccesary script in the master page.  I'm thinking that the GetCurrent() method might do the trick; just not sure how to implement it.

Thanks,

Shaun.
0
Iurii
Top achievements
Rank 1
answered on 26 Apr 2007, 05:23 PM
Leon, I have read the documentation and I completely understand that I need script manager on each page. However, because you can have only one script manager per page, i can not include it in my user controls.

Now, since i don't have scriptmanager in my usercontrol, any instance of ajaxloadingPanel errors out design time. Runtime everything works just fine.

Let's see what Telerik support will say.
0
surfer
Top achievements
Rank 1
answered on 26 Apr 2007, 05:45 PM
Looking at Reflector, GetCurrent is a public method of RadAjaxManager which retrieves the AjaxManager instance per page. The code is:

public static RadAjaxManager GetCurrent(Page page)
{
    if (page == null)
    {
        throw new ArgumentNullException("page");
    }
    return (page.Items[typeof(RadAjaxManager)] as RadAjaxManager);
}

if basically, checking Page.Items[typeof(RadAjaxManager)] will give you the instance of the AjaxManager (or null if no AjaxManager is available)
0
Ken Fleming
Top achievements
Rank 1
answered on 01 May 2007, 04:37 PM
How does a C# method help in a javascript.
I am getting the error Object doesn't support this method when I try to use AjaxRequest in a user control loaded onto the page in which the RadAjaxManager is declared.
0
Ken Fleming
Top achievements
Rank 1
answered on 01 May 2007, 05:04 PM
Ok, GetAjaxEventReference worked in this particular instance, but I think the Prometheus Ajax needs better documentation.  I have not been able to get a javascript to work in a user control yet.
0
Vlad
Telerik team
answered on 02 May 2007, 03:23 PM
Hello,

You can get the ajax manger client-side object using $find("<%= RadAjaxManager1.ClientID %>").

Best wishes,
Vlad
the telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Jonathan
Top achievements
Rank 1
answered on 02 Aug 2007, 02:14 PM
Hi,

I am having this same problem with the Prometheus Ajax control.  My javascript gives me an error 'Object doesnt support this property or method' when trying to access the 'AjaxRequest' method of the AjaxManager.  I can access the AjaxManager, but cannot call the function.

I also cannot use the suggested workaround of putting "<%= AjaxManager.ClientID %>" in my code as my page is almost entirely created dynamically and you cannot use code blocks in the aspx if you are dynamically adding controls.

Can anyone suggest another workaround for this?  Its driving me mad because I cant understand why I can happily access my AjaxManager instance yet cannot call the AjaxRequest function with it?

Any help massively appreciated.
0
Sebastian
Telerik team
answered on 03 Aug 2007, 01:55 PM
Hello Jonathan,

I suggest you take advantage of the RadAjaxManagerProxy feature introduced in the latest version of RadAjax "Prometeus" to bypass the problem with the AjaxRequest event execution you are currently facing.

For your convenience I have prepared a sample web site which loads user control dynamically on the main page. The main page wraps ScriptManager and RadAjaxManager instances while the user control encapsulates RadAjaxManagerProxy with settings adding programmatically on PageLoad. The result will be that a label's text will be updated with the selection made in the dropdown list control.

Feel free to use the same technique when building controls programmatically in your project.

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Jonathan
Top achievements
Rank 1
answered on 03 Aug 2007, 02:07 PM
Thanks for the reply and the attached code which I will try out.  I had noticed the RadAjaxManagerProxy but didnt realise this could help me out. 

Hopefully this will sort out my problem.
0
MB
Top achievements
Rank 1
answered on 13 Aug 2007, 12:30 AM
I'm afraid that I'm a complete idiot, as I STILL don't understand how the server-side events work with the RadAjaxManager and RadAjaxManagerProxy.

Although the sample above doesn't actually use the Masterpage, I assume that if using a MasterPage you insert the RadAjaxManager on the MasterPage, similar to the way you insert a single ScriptManager, and then use the RadAjaxManagerProxy on child Pages & Controls

However... who and what handles the AjaxRequest() events, and where ??

I am trying to build an example for myself, so I can come to grips with how this all works, and I decided to build something similar to:
http://www.telerik.com/community/code-library/submission/b311D-hbagd.aspx 

However, I want to place the grid and all the behind code on a UserControl, which is then placed onto a Page, which is then placed onto a MasterPage, as this better emulates my site.

I assume that I would place the ScriptManager and RadAjaxManager on the Masterpage ??

I then assume I would need a ScriptManagerProxy and RadAjaxManagerProxy on the UserControl.

.. and then... the AjaxRequest delegate goes... where??  and is applied to what ??

Sorry for sounding like such a dummy, but I don't seem to be able to conceptualize the single RadAjaxManager and how that works when multiple controls and/or pages might be making AjaxRequests().
0
MB
Top achievements
Rank 1
answered on 14 Aug 2007, 01:58 AM

Ok... I think that the penny has partially dropped for me, and I've worked this out, to some extent.

It's a bit clunky, but I managed to deal with it by adding specific delegates to the single AjaxManager from within the UserControl that I want to handle a specific AjaxRequest event, at the UserControl level.

Something like:

public partial class MyControl : System.Web.UI.UserControl  
{  
  protected void Page_Init(object sender, EventArgs e)  
  {  
    ...bla bla bla...  
 
    Telerik.Web.UI.RadAjaxManager RadAjaxManager1 = (Telerik.Web.UI.RadAjaxManager) this.Page.Master.FindControl("RadAjaxManager1");  
 
    RadAjaxManager1.AjaxRequest += new Telerik.Web.UI.RadAjaxControl.AjaxRequestDelegate(this.RadAjaxManager1_MyControlLevelAjaxRequest);  
 
    ...bla bla bla...  
  }  
 
 
  protected void RadAjaxManager1_MyControlLevelAjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)  
  {  
    ...bla bla bla...  
  }  

I still seem to require the standard delegate at the MasterPage level, even if it does nothing.

Although I haven't tested it, I assume that any other delegate I add at other pages and UserControls would also fire for any AjaxRequest fired from the Client... so I would need to test each event and exit.

I'm still not sure if this is the "right" solution, but it does work. However, it's a bit on the clunky side, and being able to target specific delegates would obviously be better, so I'm sure that I'm still missing a basic point here.

Tags
Ajax
Asked by
Yuri
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Iurii
Top achievements
Rank 1
Leon
Top achievements
Rank 1
Shaun Peet
Top achievements
Rank 2
surfer
Top achievements
Rank 1
Ken Fleming
Top achievements
Rank 1
Jonathan
Top achievements
Rank 1
Sebastian
Telerik team
MB
Top achievements
Rank 1
Share this question
or