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

Loading UserControl

11 Answers 214 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Janu
Top achievements
Rank 1
Janu asked on 09 Apr 2009, 09:16 PM
Hello i am Faisal and i am facing some issues while loading usercontrols.
In my application i've successfully loaded usercontrols through AJAX(telerik ofcourse) and now my issue is i want to load a usercontrol multiple times.
For example: There is a usercontrol named "detail.ascx" and in this control there are only labels nothing else which is showing customer name, address, balance etc and if i click button the detail.ascx should be loaded 3 times and sometime 4 times (it depends) so please tell me how to load usercontrol multiple time so that i can view detail.ascx multiple times in a single page. Please let me know if it is possible in AJAX.

Thanks :)
Faisal Rehman

11 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 10 Apr 2009, 03:54 PM
Hi Janu,

Find more information about loading User controls with RadAjax in the following articles:
RadAjax and WebUserControls
Load user controls
Loading User Controls-Demo

All the best,
Pavlina
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
TonyG
Top achievements
Rank 1
answered on 30 Apr 2009, 04:50 AM
It seems like this is a FAQ but I'm having a hard time figuring this out myself.

I have a user control with a textbox, a couple buttons, and a label.  Enter text, click a button, the label is set.
The usercontrol is structured as follows:
    <RadAjaxPanel>....my controls...</RadAjaxPanel>
So I expected that each user control would operate autonomously from whatever parent page makes use of them.

A simple page has a RadScriptManager and with nothing but the same usercontrol added a few times with public properties set to invoke different behavior.  It looks like initializers are firing for all instances of the usercontrol whenever an event is fired on any of them.  When the entire page is submitted then I'll extract data from all controls, but until then there should be no link between these controls.

What am I missing?
Thanks!
0
Pavlina
Telerik team
answered on 30 Apr 2009, 04:21 PM
Hi Tony,

From the information provided so far I am not able to determine the exact source of the issue you are facing. At this point I will ask you to open a formal support ticket and send us a small runnable application. Thus I could do all my best to find a quick resolution of this matter.
 
Sincerely yours,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
TonyG
Top achievements
Rank 1
answered on 30 Apr 2009, 08:33 PM

I understand that lack of information makes it impossible to answer many questions.  Perhaps the answer to this general question will help:  What's the proper pattern for putting multiple instances of a given user control onto a Rad-enabled form?

Here is what I have for two controls exhibiting the same behaviour:

Form.aspx:
<html>...<RadScriptManager/><uc1:mycontrol1/><uc2:mycontrol2/></html>

MyControl.ascx:
<div><RadAjaxPanel>...controls...</RadAjaxPanel></div>

When an event is fired on any instance of the control, all of the instances re-initalize on the server, and then the event is fired on the specific instance.  It looks like any event creates a postback for all controls.

 

In the LoadUserControls example, there is no RadAjaxPanel in the usercontrol.  I just wanted to make sure my control is Ajax-aware so that I didn't need to manage ajaxification in the container.  Is that overkill?

Thanks again.

0
TonyG
Top achievements
Rank 1
answered on 30 Apr 2009, 10:23 PM
Ahh, I see the pattern is this:

Form.aspx:
<html>...<RadScriptManager/><RadAjaxManager/>
<asp:Panel ID="Panel1"><uc1:mycontrol ID="c1"/></asp:Panel>
<asp:Panel ID="Panel2"><uc1:mycontrol ID="c2"/></asp:Panel>
</html>

MyControl.ascx:
...nothing but controls...

Then use the RadAjaxManager to have Panel1 update Panel1, Panel2 update Panel2, etc.

My problem related to this is fixed.  Now I can move on to diagnosing other weird behaviours.  :)

Thanks.
0
Pavlina
Telerik team
answered on 05 May 2009, 04:23 PM
Hi Tony,

I suggest that you try to replace RadAjaxPanel which you use inside a WebUserControl with RadAjaxManagerProxy control and configure it in the same way as the AjaxPanel to AJAX-enable the user control completely.
 
Note that we highly recommend avoid working with the RadAjaxManager and RadAjaxPanel controls at the same time.

Please give this suggestion a try and let me know how it goes and if any other questions
arise.

bEST,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
TonyG
Top achievements
Rank 1
answered on 05 May 2009, 09:15 PM
Pavlina - blagodaria / spaciba / thanks / dankon  :)     (anyone there speak Esperanto?)

I've shifted the development of this new site to masterpages with a single manager in the master, a limited number of content pages hosting dynamic user controls, and user controls that manage their own activity with a manager proxy.  So far this is working well though the added complexity was initially painful to implement.

The thing to remember about all of this is: if you're getting full postbacks instead of partials, try wrapping your controls in a panel or div.  That includes content pages, placeholders, and user controls.  I don't completely understand this behaviour and it would really help to see a blog or help page that explains in-depth what we should do under various circumstances, and why.
0
Pavlina
Telerik team
answered on 07 May 2009, 01:59 PM
Hi TonyG,

When you need to ajaxify a control with RadAjaxManager, you need to make sure is it available and visible on the page all the time. As dynamic user controls are not always available on the page, it is suggested that you ajaxify their parent container instead of themselves.

For more information, refer to the following articles:
Add AjaxSettings programmatically
Show RadAjaxLoadingPanel on initial page load

Greetings,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
TonyG
Top achievements
Rank 1
answered on 07 May 2009, 08:44 PM
Thanks again.  Note from my last post that I did replace the RadAjaxPanel and I'm not using them anymore.  When a postback is done and you have controls nested in content pages in a master page, the user control isn't on the page as far as the server is concerned.  to my understanding it needs to be reloaded so that events can be processed.

As far as wiring, I've found that nested components don't always show up in the RadAjaxManagerProxy when they're inside a Panel - the designer code isn't looking within the controls of all panels, and if you have nested dynamic UCs the designer wouldn't know about them anyway.  So rather than using the proxy designer at all anymore, I've created a standard method to be executed at PreRender time for all controls and pages, to programmatically AddAjaxSettings for all required controls in any given control set.

As far as ajaxifying entire Panels that contains controls, I've been thinking that doing this would cause all controls in the panel to get processed on any postback, which can be overkill, so I've been trying to avoid using AddAjaxSetting(PanelX,PanelX) and I'm just specifying every required control.  Is this the correct approach?
0
ManniAT
Top achievements
Rank 2
answered on 08 May 2009, 09:32 AM
I'm not sure if it is the "correct" approach - but my UserControls take care of their own AjaxSettings.
It is something like this:
            //get the Ajax manager  
            RadAjaxManager aM = RadAjaxManager.GetCurrent(Page);  
            if (aM == null) {  
                Response.Write("XFileExplorer needs an Ajax manager in the page holding the control!");  
                Response.End();  
                return;  
            }  
            //calling Ajax function changes grid and hidden fields - so add settings  
            AjaxSetting aS = new AjaxSetting(aM.ID);  
//here add what we have to do 
So with that I can assure that the control itself (if it is composite what I assume here) can handle it's own ajax things.
If an other control on the page want's to ajaxify my usercontrol it must add the ajax settings for it.

Regards

Manfred
0
TonyG
Top achievements
Rank 1
answered on 08 May 2009, 05:10 PM
Manfred - I've also created a base class so that UCs can ajaxify themselves through the proxy which gets a reference to the base page RadAjaxManager.

It seemed to be working for a while but unfortunately now I'm finding that on every ajax postback I need to completely repopulate controls in order to process events.  For a grid in a UC on a panel on a content page within a master, there is no selected item when processing events.  I'm sure I'm doing something dreadfully wrong now, and while I've been learning a lot over the last week I really need to move forward with this stuff.

Manfred, I sent you a Skype note to discuss for-fee consulting.  I'll try to email at PPP.
Tags
Ajax
Asked by
Janu
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
TonyG
Top achievements
Rank 1
ManniAT
Top achievements
Rank 2
Share this question
or