Load usercontrol by AjaxEvents

  1. #1

    Load usercontrol by AjaxEvents


    Hi,

    can I load my user controls by AjaxEvents? Please look a t my code below.

    It works in the page_load but it does not work in the AjaxMethod.


    LeftMenu.ascx
    
    <ext:MenuPanel ID="MenuPanel1" runat="server" Title="Modules" Icon="ArrowSwitch">
                  
                     <Menu>
    
                        <Items>
                            <ext:MenuItem ID="NewModule"  runat="server" Text="Add new Module" Icon="ArrowRight" />
                            <ext:MenuItem ID="ModuleList"  runat="server" Text="Module List" Icon="ArrowRight" />
                            <ext:MenuItem ID="ModulePlacement" runat="server" Text="Change module place" Icon="ArrowRight" />
                        </Items>
                       
                        <AjaxEvents>
                            <ItemClick OnEvent="MenuItemClickAjax" >
                            <EventMask ShowMask="true" />
                            <ExtraParams>
                                <ext:Parameter Name="title" Value="e.text" />
                            </ExtraParams>
                                
                            </ItemClick>
                        </AjaxEvents>
                                                             
                    </Menu>                                        
                </ext:MenuPanel>
    
    
            [AjaxMethod]
            protected void MenuItemClickAjax(object sender, AjaxEventArgs e)
            {
                Control uc = LoadControl("~/UserControls/ModuleList.ascx");
                MasterPage mainPage = this.Parent.Page.Master;
                ContentPlaceHolder ph = mainPage.FindControl("cphMiddle1") as ContentPlaceHolder;
                ph.Controls.Add(uc);
            }

    Do you have any idea?

    All suggestions are welcome.

    Thank you in advance.





  2. #2

    RE: Load usercontrol by AjaxEvents

    Hi Latif.

    If I'm not mistaken, you can't load UserControls wiith Ahjax Calls BUT you can place the the UControl in the markup page
     <UC:MyUserControl runat = "server" ID=... />
    and set its visibility fo false.
    When you need the control to be visible, simply change the visibility; it should work.

    Bye,

    Lorenzo
  3. #3

    RE: Load usercontrol by AjaxEvents

    Hi Lorenzo,

    Thank you for your reaply.

    I will try your solution but by this solution I have to load all my user controls on page load. And I think i will effect my page speed. So I believe that it would be better to do it via AjaxMethod so you will be able to load it when the user control requested(by clicking each menu items).

    Therefore is there any other alternatives?

    I thought, the code below would work. but unfortunately!


            [AjaxMethod]
            protected void MenuItemClickAjax(object sender, AjaxEventArgs e)
            {
                Control uc = LoadControl("~/UserControls/ModuleList.ascx");
                MasterPage mainPage = this.Parent.Page.Master;
                ContentPlaceHolder ph = mainPage.FindControl("cphMiddle1") as ContentPlaceHolder;
                ph.Controls.Add(uc);
            }

    Thank you..

  4. #4

    RE: Load usercontrol by AjaxEvents

    Hi Latif.


    I was quite sure as I had the same requirement sometime ago but I've double checked if I was right or not and, unfortunately, I think Vlad already confirmed what I reported to you here:

    http://forums.ext.net/showthread.php?postid=17421.aspx


    I think this limit is due to the mechanism Asp.Net uses to create the compiled page class.




    Lorenzo
  5. #5

    RE: Load usercontrol by AjaxEvents

    Hi Lorenzo.

    As far as I can see. It is not possible to do it by ajax event for now.

    So I should do it without ajax event for the time being. I will again consider on this way later on.

    Thank you for your concern.

Similar Threads

  1. Load Usercontrol on DesktopModule
    By Kaveh in forum 2.x Help
    Replies: 6
    Last Post: Apr 28, 2012, 4:59 AM
  2. regarding usercontrol load in runtime
    By ranjit2k99 in forum 1.x Help
    Replies: 22
    Last Post: May 30, 2011, 1:38 PM
  3. Replies: 0
    Last Post: Apr 04, 2011, 6:05 PM
  4. load usercontrol in viewport
    By maxdiable in forum 1.x Help
    Replies: 1
    Last Post: Jul 28, 2010, 11:01 PM
  5. [CLOSED] delay in ajaxevents in IE with a UserControl
    By maras54 in forum 1.x Legacy Premium Help
    Replies: 9
    Last Post: May 31, 2009, 9:38 PM

Posting Permissions