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

RadAjaxManagerProxy in user control

14 Answers 1520 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Tom
Top achievements
Rank 1
Tom asked on 17 Jan 2008, 01:21 AM
Hello,

I am using the 

telerik:RadAjaxManager

in my main.aspx page which, in turn, loads usercontrols. In my usercontrol I have a 

RadTabStrip

which also calls other usercontrols which i also want  AJAXified. So I'm trying the RadAjaxManagerProxy but as soon as I put in my user control I get this error message:

Server Error in '/' Application.
--------------------------------------------------------------------------------

Collection was modified; enumeration operation may not execute.

Any clues?

Thank you

14 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 17 Jan 2008, 11:45 AM
Hi Tom,

This error should not be directly related to the Ajax controls. Are you by any chance using a foreach loop to modify a collection? Note that it's not allowed to modify a collection within a foreach loop. Google shows numerous threads with the same error caused by foreach loop.

Let us know if further help is needed.

Kind regards,
Steve
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Tom
Top achievements
Rank 1
answered on 17 Jan 2008, 02:49 PM
Hi,

No I have no code behind in my pages yet. I have a tabstrip, a pageview in my usercontrol and that's what I'm trying to ajaxify. Ultimately what I need is to be able to load only the usercontrol called when I click on its tab. I have the main page already containing a radajaxmanager which calls this usercontrol.

Main page (already with radajaxmanager prometheus)
    -usercontrol A-with tabstrip and pageview
            -usercontrol (child)
            -usercontrol (child)
             -usercontrol (child)
             -usercontrol (child)


USERCONTROL A :

<radTS:RadTabStrip Height="26px" ID="rtsMain" runat="server"   MultiPageID="rmpMain" SelectedIndex="0" Skin="MYCA" Width="706px" meta:resourcekey="rtsMainResource1" >
  <Tabs>
   <radTS:Tab ID="tabHh" runat="server"  PageViewID="pvHh" Text="<%$ Resources:healthRecord, tabHhResource %>"></radTS:Tab>
   <radTS:Tab ID="tabAll" runat="server" PageViewID="pvAll" Text="<%$ Resources:healthRecord, tabAllResource %>"></radTS:Tab>
   
  </Tabs>
 </radTS:RadTabStrip>
 <!-- AJAX MANAGER-->
 <asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server" />
        <telerik:RadAjaxManagerProxy ID="AjaxManagerProxy1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="tabAll">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="pvAll" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManagerProxy>
       
 
 <!-- SECTION MAIN CONTENT 710PX AND 990PX AVAILABLE -->
 <div class="bg710">
  <!--CONTENT LEFT-->
  <div class="content">
   <radTS:RadMultiPage ID="rmpMain" runat="server" SelectedIndex="0"  AutoScrollBars="True" Width="694px" meta:resourcekey="rmpMainResource1" PageViews-Capacity="8">
    <radTS:PageView ID="pvHh" runat="server" Width="694px" ></radTS:PageView>
    <radTS:PageView ID="pvAll" runat="server"  Width="694px"><myca:allergies id="allergies"  runat="server"  ActiveOptions="2"></myca:allergies></radTS:PageView>
   </radTS:RadMultiPage>
  </div>
 </div>
0
Steve
Telerik team
answered on 18 Jan 2008, 10:44 AM
Hello Tom,

You cannot ajaxify PageViews and you should set as updated control the whole MultiPage. Reading your explanation it is not clear what do you mean by "already containing a radajaxmanager which calls this usercontrol" Note that user controls do not render any html in the output and this is crucial for the RadAjaxManager control to function properly. Instead of referencing the user control, you can wrap it in some container (asp:Panel, div etc) and add this control to the AjaxSettings as well. More info is available in this help article.

Regards,
Steve
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Matthew Erwin
Top achievements
Rank 1
answered on 14 Apr 2008, 09:15 AM
This can in fact be done without doing something as tremendously wasteful as re-posting an entire tab-control and all of its contents back to the server. I have spent a colossal amount of time dealing with the abominable shortcomings of the Ajax here (particularly as it pertains to the combination of MasterPages/Content & User Controls -- then just try adding LoadControl and  TabStrip in that mess and you get the picture).

I'm sorry but I have to say that the suggestion of posting back the entire multi-page view as a solution is about the dumbest "Ajax" solution I've ever heard...at that point why wouldn't you just post back the whole page?! Speaking of which this library could REALLY use the ability to call an ASMX Web Service instead of doing partial postbacks to the original rendering page (ala through Microsofts proxy generation)....but that is aside from this post.

Having come across a number of articles where people appeared to be frustrated trying to accomplish some combination of what I described in my initial paragraph I thought it would be worth the bother to post an actual workable solution to deal with this. I'm going to guess that these horrible headaches are due to the fact that the RadAjaxManagerProxy doesn't chain so you can't have a proxy to the proxy (e.g. RadAjaxManager in Master Page, Proxy in Content page and Proxy in User Control and Proxy in sub-User Control).

So...with no more further ado...

Drop an RadAjaxManager into your MasterPage such as the following:
<form id="aspnetForm" runat="server"
<telerik:RadScriptManager ID="MasterRadScriptManager" runat="server" EnableScriptCombine="true"></telerik:RadScriptManager> 
<telerik:RadStyleSheetManager ID="MasterRadStyleSheetManager" runat="server" EnableStyleSheetCombine="true"></telerik:RadStyleSheetManager> 
 
<telerik:RadAjaxManager ID="MasterAjaxManager" runat="server" DefaultLoadingPanelID="LoadingPanel" > 
<AjaxSettings/> 
</telerik:RadAjaxManager> 
 
<telerik:RadAjaxLoadingPanel ID="LoadingPanel" runat="server" Transparency="30"
<asp:image ID="Image1" ImageUrl="~/RadControls/AJAX/Skins/Default/LoadingProgressBar.gif" BorderWidth="0px" Runat="server"></asp:image> 
</telerik:RadAjaxLoadingPanel> 
 
     
    <asp:ContentPlaceHolder id="PageContent" runat="server"
    </asp:ContentPlaceHolder> 
</form> 

Then in the code-behind (e.g. MyMaster.master.cs):

    public RadAjaxManager AjaxManager 
    { 
        get { return this.MasterAjaxManager; } 
    } 


In your ASPX content pages that reference this master page you just add another property such as:

    public RadAjaxManager AjaxManager 
    { 
        get { return (this.Master as MasterPages_MyMaster).MasterAjaxManager; } 
    } 


Then basically you will need to make sure each User Control you want to use has a reference to this same RadAjaxManager -- I basically just create a public property on the user controls that I set during Page_Load of the ASPX. It is VERY important to always set your AjaxSettings on both PostBack and initial page hit.

These are the additions to the ASCX:

    private RadAjaxManager _radAjaxManager = null
    public RadAjaxManager AjaxManager 
    { 
        set { _radAjaxManager = value; } 
        get { return _radAjaxManager; } 
    } 


    protected void Page_Load(object sender, EventArgs e) 
    { 
        //MUST BE SET EVERY TIME!!! 
        AjaxSetting ajaxSetting = new Telerik.Web.UI.AjaxSetting("HistoryGrid"); 
        ajaxSetting.UpdatedControls.Add(new AjaxUpdatedControl("HistoryGrid""LoadingPanel")); 
        AjaxManager.AjaxSettings.Add(ajaxSetting); 
    } 


One very important point here is that I saw numerous articles talking about either calling the method AjaxSettings.AddAjaxSetting( ctrl1, ctrl1, loadingStr ) or specifying the control string using the full mangled name (either in the master page or the containing page). I have tried every combination and this is the ONLY one I found that worked for complex scenarios involving Master Pages, ASPX and ASCX. Using mangled names didn't get me anywhere. You can obviously add as many items to the settings as you want as well as forward the reference as deep as you need to. I'm sure this is what the AjaxManagerProxy was designed to do (just percolate the settings up to the main controller) but it appears to fail to do that except in very cut & dry scenarios (which Telerik has happily put on the online demos section).

Don't get me wrong...I'm not bashing the product at all -- this is the best ASPX library I've used (DevExpress may have you guys in a number of categories but they also charge per server licensing). You guys have done a stellar job putting together this product.

I would love to see these complex scenarios addressed shortly after Prometheous hits RTM:

  1. Support and demos for Master Pages with a Content control that contains a Tab Strip which contains User Controls that contain Ajax and RadGrid and then some sub User Controls that also contain Prometheous controls that are ajax-enabled. (Preferably supporting percolation of Ajax settings via the Proxy as it appears was the original intent of that structure).
  2. Ability to use ASMX scripted web services (i.e. myservice.asmx/js) to grab content for things like the Grid particularly since the Client-side functionality is a bit lacking. TreeView can be completely integrated with ASMX scripted web services client-side....unfortuantely 98% of people primarily use grids on their pages with the occasional need for a Tree View.
  3. And PLEASE....PLEASE....would you add support to allow me to a cache a control that I load via LoadControl? It would make such a huge performance impact. I cannot stress enough how important it is particularly given the fact that user controls still execute even if disabled or not visible. As it is now we pay a penalty if we have them in the page due to the postbacks to the page or we pay the penalty of having to call LoadControl (ultra-slow) every time we want to use a control. Caching. Caching. Caching. Would be awesome! Thanks

Thanks again for a great product at a reasonable price and for the tremendously helpful forum. I learned a 100 ways that didn't work on my way to finding one that did but I find that the number of people contributing to this forum has made it one of the most valuable I've ever used.

Cheers,
Matteo
0
Officialboss
Top achievements
Rank 1
answered on 23 Apr 2008, 08:55 PM
Matt brings out some excellent points which I too was trying to figure out until I read his post. I will be looking forward to the implementation on what Matt has suggested.

Thanks.
0
Vlad
Telerik team
answered on 24 Apr 2008, 12:47 PM
Hi guys,

There is no need to implement such property in your content pages, user controls, etc. - you can access the manager using RadAjaxManager.GetCurrent(Page) static method.

@Matteo:

Firstly I want to thank you for your precious feedback and nice words about our product.

- If you have an example where you cannot use
AddAjaxSetting() method just let us know. You can submit small example via support ticket with few explanations about desired effect and we will get back to you with more info.
Especially for TabStrip/Multipage you can check this link:
http://www.telerik.com/DEMOS/ASPNET/Prometheus/TabStrip/Examples/ApplicationScenarios/LoadOnDemand/DefaultCS.aspx

RadGrid is a bit more complex ASP.NET control (CompositeDataBoundControl) and unfortunately providing features like client-side creation from a web service will lead immediately to lots or problems including: server-side templates, server-side data-bindings, rich client-controls (here the situations is serious .. let say that you have RadEditor inside a grid template - this control should be cloned completely client-side) and of course even simple post-back button will be one of the biggest challenges. You will unable to fire simple post-back event from client-side cloned control - the framework actually will raise EventValidationException.

Controls loaded or created normally will be cached automatically in the ViewState - this should be done before LoadViewState() (more info can be found here (Control Execution Lifecycle) or here (TRULY Understanding Dynamic Controls)) in all other situations (post-back events most probably in your case) you should reload/recreate these controls. Recreating controls created on post-back events can be really tricky and for reference you can check famous DynamicControlsPlaceholder developed by Denis Bauer few years ago.

Don't hesitate to contact us if you have other questions or problems.

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Erick
Top achievements
Rank 1
answered on 19 Nov 2008, 06:01 PM
Vlad,

You mention that "There is no need to implement such property in your content pages, user controls, etc. - you can access the manager using RadAjaxManager.GetCurrent(Page) static method."

Is there a good example of using RadAjaxManager.GetCurrent(Page) where the RadAjaxManager is in the Master page and I need to access it from a WebUserControl?  I cannot find any example and when I try the RadAjaxManager.GetCurrentPage(Page) in the WebUserControl, it always comes back as null.

Erick
0
Sebastian
Telerik team
answered on 20 Nov 2008, 09:51 AM
Hello Erick,

I think that you can combine the logic from these two online demos of the product:

http://demos.telerik.com/ASPNET/Prometheus/Ajax/Examples/Manager/MasterPage/DefaultCS.aspx
http://demos.telerik.com/ASPNET/Prometheus/Ajax/Examples/Manager/UserControl/DefaultCS.aspx

to get reference to the RadAjaxManager instance (which resides in the master page) from your user control.

Best regards,
Stephen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Erick
Top achievements
Rank 1
answered on 20 Nov 2008, 04:48 PM
I have looked over both those examples a number of times and cannot figure out how to "combine the logic" to make it work.  The first example has the RadAjaxManager on the master page and the RadAjaxManagerProxy on the content page (aspx).  The second example has the RadAjaxManager on the content page (aspx) and the RadAjaxManagerProxy on the web user control (ascx).  Maybe I'm missing something, but I cannot figure out how to make it work with the RadAjaxManager on the master page and the RadAjaxManagerProxy on the web user control (ascx).  Are there any specific examples for that scenario?
0
Maria Ilieva
Telerik team
answered on 21 Nov 2008, 08:02 AM
Hi Erick,

Please review the following help topics which represents the required functionality:

RadAjax and WebUserControls
AJAX Manager Proxy




Greetings,
Maria Ilieva
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Erick
Top achievements
Rank 1
answered on 21 Nov 2008, 09:10 PM
Thanks for the quick replies!

After hours of banging my head against the wall, I finally figured out what I was doing wrong.

On my master page, the ScriptManager was BELOW the RadAjaxManager.  Once I moved it ABOVE the RadAjaxManager, everything works correctly!

I guess I never realized that the order those are on the page makes a difference, but that is a lesson that i will never forget!

Thanks again for your patience and help.

Erick
0
Christian Bruckhoff
Top achievements
Rank 1
answered on 16 Jul 2010, 02:47 PM
This is without a doubt the dumbest update to RadAjaxManager to date.  An easy to use control has been made complicated.
0
Boot
Top achievements
Rank 1
answered on 06 Apr 2011, 05:49 PM
I have to agree with Toby.
0
Bodevain Svensson
Top achievements
Rank 1
answered on 07 Apr 2011, 08:30 AM
Guys, I do not understand what update of the ajax manager you have in mind. Common practice is that the asp ScriptManager (or RadScriptManager respectively|) should be positioned as first control inside the form as it manages the AJAX scripts loading and registration. Honestly I do not see any point in arguing that.

-B
Tags
Ajax
Asked by
Tom
Top achievements
Rank 1
Answers by
Steve
Telerik team
Tom
Top achievements
Rank 1
Matthew Erwin
Top achievements
Rank 1
Officialboss
Top achievements
Rank 1
Vlad
Telerik team
Erick
Top achievements
Rank 1
Sebastian
Telerik team
Maria Ilieva
Telerik team
Christian Bruckhoff
Top achievements
Rank 1
Boot
Top achievements
Rank 1
Bodevain Svensson
Top achievements
Rank 1
Share this question
or