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

AjaxManager + Dynamic Controls problems

5 Answers 239 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Sergey
Top achievements
Rank 2
Sergey asked on 23 Mar 2010, 03:38 PM
Okay, going to try and describe this as clearly as possible, since it's a bit of a complicated situation.

This is for VS2010, .NET 4.0, Telerik Q1-2010 release. 

The setup is as follows, there's a master page, with a content page. The master page has an ajaxmanager and the content page has a proxyajaxmanager. The content page has user controls, amongst other things. 

The goal is as follows: there's a linkbutton on the content page, that when clicked adds a user control to a panel on the content page. 

The problem: the linkbuttons are dynamically added, as in: 
var li = new LinkButton 
                { 
                    Text = action.Name, 
                    ToolTip = action.Description, 
                    ID = "al" + action.ReportActionTypeID, 
                    EnableViewState = false 
                }; 
                li.Click += ActionTrigger; 
                
                ActionPanel.Controls.Add(li); 

So, after that, I attempt to add them to the Ajaxmanager from code behind (doing it through longer way of constructing and using Add instead of AddSetting, because AddSetting was throwing a null reference error that I never managed to figure out):
var ajaxSetting = new AjaxSetting(); 
                var target = new AjaxUpdatedControl(ActionPanelDynamic.ID, "AjaxLoadingPanel"); 
                ajaxSetting.UpdatedControls.Add(target); 
                ajaxSetting.AjaxControlID = li.ID; 
                _ajaxManager.AjaxSettings.Add(ajaxSetting); 

The code executes with no issues, however, the AJAX is not applied as expected. It just does a full page refresh when one of the linked buttons is clicked. 

I've tried to apply settings to a static linkbutton (one that I just added in markup), and this functions as expected. 

My guess at this point is that the IDs of controls are just incorrect at some point? As ASP renames them, and there are some empty string warnings for GetElementByID in FireBug console. But I'm not really sure at what point or where to correct this. I was thinking this http://west-wind.com/weblog/posts/54760.aspx may possibly be related? 

5 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 23 Mar 2010, 05:33 PM
Hello Sergey,

Please have in mind that when the RadAjaxManager control is used in dynamically loaded user control, you should create RadAjaxManager on Page_Init event and after that add AjaxSettings on Page_Load or Page_PreRender.

GIve this suggestion a try and let me know about the result.

Greetings,
Pavlina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Kevin Kembel
Top achievements
Rank 1
answered on 25 Apr 2010, 06:06 AM
Hi,

I'm having a very similar problem.

I have an AjaxManager in my main page, and I have a "search" textbox in a panelbar on my main page as well.  I add the "search" button to my ajax manager programmatically when the search button loads:
        // Add the ImageButton for search into the ajax manager 
        // so that it updates the content 
        ImageButton searchButton = sender as ImageButton; 
 
        // Create the ajax setting 
        Telerik.Web.UI.AjaxSetting searchAjaxSetting = new Telerik.Web.UI.AjaxSetting(); 
        searchAjaxSetting.AjaxControlID = searchButton.UniqueID; 
 
        // Create the updated control 
        Telerik.Web.UI.AjaxUpdatedControl searchUpdatedControl = new Telerik.Web.UI.AjaxUpdatedControl(); 
        searchUpdatedControl.ControlID = contentPanel.UniqueID; 
        searchUpdatedControl.LoadingPanelID = contentLoadingPanel.UniqueID; 
 
        // Add the updated control to the setting 
        searchAjaxSetting.UpdatedControls.Add(searchUpdatedControl); 
 
        // Add the setting to the ajax manager 
        ajaxManager.AjaxSettings.Add(searchAjaxSetting); 

This works fantastic, when I do a search, an ajax postback is made, and I dynamically add a "SearchResults" user control to the page's place holder (in the updated "contentPanel" control). This works, and my search results are displayed.

My problem is that my "SearchResults" user control has an event, "ResultClick" that fires when a user clicks on a search result. My main page subscribes to that event, and I want to update the "contentPanel" again through an ajax postback when that event is fired.  Problem is, when my "SearchResults" user control that gets dynamically created fires the event, it does a full postback.  I can't get my dynamic user control to register with the AjaxManager when the control itself is created through an async postback.

Here's how I generate the "SearchResults" user control, and how I attempt to register it with the AjaxManager:
                Control pageContent = LoadControl("~/UserControls/SearchResults.ascx"); 
                ((UserControls_SearchResults)pageContent).ResultClick += 
                    new UserControls_SearchResults.SearchResultEventHandler(searchResults_ResultClick); 
                pageContent.ID = "ContentSearchResults"
 
                // Add the dynamically created user control to the ajax manager 
                // so that it updates the content panel 
                Telerik.Web.UI.AjaxSetting ucAjaxSetting = new Telerik.Web.UI.AjaxSetting(); 
                ucAjaxSetting.AjaxControlID = pageContent.UniqueID; 
 
                // Create the updated control 
                Telerik.Web.UI.AjaxUpdatedControl ucUpdatedControl = new Telerik.Web.UI.AjaxUpdatedControl(); 
                ucUpdatedControl.ControlID = contentPanel.UniqueID; 
                ucUpdatedControl.LoadingPanelID = contentLoadingPanel.UniqueID; 
 
                // Add the updated control to the setting 
                ucAjaxSetting.UpdatedControls.Add(ucUpdatedControl); 
 
                // Add the setting to the ajax manager 
                ajaxManager.AjaxSettings.Add(ucAjaxSetting); 
 
                contentPlaceHolder.Controls.Add(pageContent); 

Hope this makes sense, it's also not a very straight-forward question, but the AjaxManager itself is not created dynamically, just the user controls that I want to register.

0
Kevin Kembel
Top achievements
Rank 1
answered on 26 Apr 2010, 03:46 AM
I'm not positive, but I think it's just the loading panel that I can't get working now.  I've implemented this way of creating dynamic controls and adding them to the page, and adding them to the RadAjaxManager a few times, and it looks like it works, but it won't display the loading panel.  Even if I do a defaultLoadingPanelID on the RadAjaxManager, it still won't display it (but does work fine for other ajax postback controls that aren't dynamically created on the page).

I still can't get my original user control I posted about to do async posts at all, but I think it's just because of my lack of understanding of how to implement postbacks manually.  My original user control that I posted about, the "Search Results" control implements IPostBackHandler for some custom events, and it won't do any async.  I haven't looked into it, but I'm assuming I'm missing an implementation.
0
Pavlina
Telerik team
answered on 28 Apr 2010, 03:26 PM
Hi Kevin,

If the issue still persists, you can open a formal support ticket, and send us a small working project, demonstrating your logic, and the unwanted behavior. Once we can reproduce the problem locally, we will do our best to help.

Best wishes,
Pavlina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Kevin Kembel
Top achievements
Rank 1
answered on 29 Apr 2010, 08:36 PM
Hi Pavlina,

Thank you for the offer, and I may take you up on that.  For the time being, I've placed all of my dynamically created controls into a panel container, and set the panel itself as an ajax control in the ajaxmanager settings.  It works for my scenario, any controls added to the panel dynamically do their postbacks through ajax.  I'm limited with the inability to add custom updatedcontrols based on what the panel contains, but it will work for me for now.

Thanks again,

Kevin
Tags
Ajax
Asked by
Sergey
Top achievements
Rank 2
Answers by
Pavlina
Telerik team
Kevin Kembel
Top achievements
Rank 1
Share this question
or