Loading UserControl

12 posts, 0 answers
  1. Janu
    Janu avatar
    2 posts
    Member since:
    Aug 2007

    Posted 09 Apr 2009 Link to this post

    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
  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 10 Apr 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. TonyG
    TonyG avatar
    239 posts
    Member since:
    Feb 2006

    Posted 29 Apr 2009 Link to this post

    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!
  5. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 30 Apr 2009 Link to this post

    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.
  6. TonyG
    TonyG avatar
    239 posts
    Member since:
    Feb 2006

    Posted 30 Apr 2009 Link to this post

    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.

  7. TonyG
    TonyG avatar
    239 posts
    Member since:
    Feb 2006

    Posted 30 Apr 2009 Link to this post

    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.
  8. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 05 May 2009 Link to this post

    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.
  9. TonyG
    TonyG avatar
    239 posts
    Member since:
    Feb 2006

    Posted 05 May 2009 Link to this post

    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.
  10. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 07 May 2009 Link to this post

    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.
  11. TonyG
    TonyG avatar
    239 posts
    Member since:
    Feb 2006

    Posted 07 May 2009 Link to this post

    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?
  12. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 08 May 2009 Link to this post

    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
  13. TonyG
    TonyG avatar
    239 posts
    Member since:
    Feb 2006

    Posted 08 May 2009 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017