How to load usercontrol dynamically

2 posts, 0 answers
  1. Balamurali Venkatesan
    Balamurali Venkatesan avatar
    94 posts
    Member since:
    Jul 2012

    Posted 01 Oct 2009 Link to this post

    Hi,

    We are having a tabstrip and radmultipageview with each tab being a usercontrol.Everything works fine when we load all the usercontrols on the page load of the parent page.

    Since its taking too long time to load all the user controls we need to load the user control on tab click.But when we do this the first time on tab click the control appears,but on subsequent request(Like clicking a dropdown on the user control) doesnot show the user control.it just displays a blank page.

    Any idea how we can load these user controls dynamically on tab click. We also tried the below link and it doesn't seem to be working.
    http://www.telerik.com/support/kb/aspnet-ajax/tabstrip/loading-user-controls-dynamically-on-tabclick-and-postback-from-loaded-user-control.aspx

    Each user control has its own RadajaxPanel

    Please see below our code snippet

    Parent page ASPX
    --------------------------------

    <

     

    asp:Panel ID="pnlTab" runat="server" Width="100%" >

     

     

    <telerik:RadTabStrip ID="tabStrpInstrFiles" runat="server" MultiPageID="radMultiPageInstrFileVwr"

     

     

    SelectedIndex="0" >

     

     

    <Tabs>

     

     

    <telerik:RadTab runat="server" Text="Summary" PageViewID="radPageViewSummary" Selected="true">

     

     

    </telerik:RadTab>

     

     

    <telerik:RadTab runat="server" Text="Comments" PageViewID="radPageViewComments">

     

     

    </telerik:RadTab>

     

     

    <telerik:RadTab runat="server" Text="Market" PageViewID="radPageViewMarkets">

     

     

    </telerik:RadTab>

     

     

    <telerik:RadTab runat="server" Text="Consolidation" PageViewID="radPageViewMarketsCons">

     

     

    </telerik:RadTab>

     

     

    <telerik:RadTab runat="server" Text="Product" PageViewID="radPageViewProducts" >

     

     

    </telerik:RadTab>

     

     

    <telerik:RadTab runat="server" Text="Facts" PageViewID="radPageViewFacts">

     

     

    </telerik:RadTab>

     

     

    <telerik:RadTab runat="server" Text="Period" PageViewID="radPageViewPeriods">

     

     

    </telerik:RadTab>

     

    <%

    --<telerik:RadTab runat="server" Text="Comments" PageViewID="radPageViewComments">

     

    </telerik:RadTab--

     

    %>

     

     

    </Tabs>

     

     

    </telerik:RadTabStrip>

     

     

    <telerik:RadMultiPage ID="radMultiPageInstrFileVwr" runat="server" Width="100%"

     

     

    SelectedIndex="0">

     

     

    <telerik:RadPageView ID="radPageViewSummary" runat="server" Selected="True"></telerik:RadPageView>

     

     

    <telerik:RadPageView ID="radPageViewComments" runat="server"></telerik:RadPageView>

     

     

    <telerik:RadPageView ID="radPageViewMarkets" runat="server"></telerik:RadPageView>

     

     

    <telerik:RadPageView ID="radPageViewMarketsCons" runat="server" ></telerik:RadPageView>

     

     

    <telerik:RadPageView ID="radPageViewProducts" runat="server" ></telerik:RadPageView>

     

     

    <telerik:RadPageView ID="radPageViewFacts" runat="server"></telerik:RadPageView>

     

     

    <telerik:RadPageView ID="radPageViewPeriods" runat="server"></telerik:RadPageView>

     

    <%

    --<telerik:RadPageView ID="radPageViewComments" runat="server"></telerik:RadPageView>--%>

     

     

    </telerik:RadMultiPage>

     

     

    </asp:Panel>

    CodeBehind File
    --------------------------------------

     

    protected

     

    void Page_Load(object sender, EventArgs e)

     

    {

     

    if (!this.IsPostBack)

     

    {

     

    this._presenter.OnViewInitialized();

     

    Master.ShowBanner =

    false;

     

     

     

    if (HttpContext.Current.Session["INSTR_PROJECT_NAME"] != null)

     

    {

    dbName = (

    string)HttpContext.Current.Session["INSTR_PROJECT_NAME"];

     

    }

     

    if (HttpContext.Current.Session["INSTR_PROJECT_Type_NAME"] != null)

     

    {

    dbTypeName = (

    string)HttpContext.Current.Session["INSTR_PROJECT_Type_NAME"];

     

    }

     

    this.lblDatabaseName.Text = this.lblDatabaseName.Text + " " + dbTypeName + " - " + dbName;

     

    }

     

    if (HttpContext.Current.Session["INSTR_ID"] != null)

     

    {

    dbId = (

    int)HttpContext.Current.Session["INSTR_ID"];

     

    }

     

    //Set the Pageview for Summary

     

     

     

     

    radMultiPageInstrFileVwr.PageViews[0].Controls.Add(LoadControl(

    "~/Instr/InstrSummaryControl.ascx"));

     

     

    //Set the Pageview for Comments

     

     

     

     

    radMultiPageInstrFileVwr.PageViews[1].Controls.Add(LoadControl(

    "~/Instr/InstrCommentControl.ascx"));

     

     

    //Set the Pageview for Market

     

     

     

     

    radMultiPageInstrFileVwr.PageViews[2].Controls.Add(LoadControl(

    "~/Instr/InstrMarketControl.ascx"));

     

     

    //Check if Market or Index Consolidation Exists

     

     

     

     

     

    int consolidationCount=this._presenter.CheckConsolidationExists(dbId);

     

     

    if (consolidationCount==0)

     

    {

     

    //Hide the Consolidation tab

     

     

     

     

    tabStrpInstrFiles.Tabs[3].Enabled =

    false;

     

    }

     

    else

     

     

     

     

    {

    tabStrpInstrFiles.Tabs[3].Enabled =

    true;

     

    radMultiPageInstrFileVwr.PageViews[3].Controls.Add(LoadControl(

    "~/Instr/InstrConsolidationControl.ascx"));

     

    }

     

    //Set the Pageview for Consolidation

     

     

     

     

    radMultiPageInstrFileVwr.PageViews[4].Controls.Add(LoadControl(

    "~/Instr/InstrProductControl.ascx"));

     

     

    //Set the Pageview for Fact

     

     

     

     

    radMultiPageInstrFileVwr.PageViews[5].Controls.Add(LoadControl(

    "~/Instr/InstrFactControl.ascx"));

     

     

    //Set the Pageview for Period

     

     

     

     

    radMultiPageInstrFileVwr.PageViews[6].Controls.Add(LoadControl(

    "~/Instr/InstrPeriodControl.ascx"));

     

     

    //Set the Pageview for Comments

     

     

     

     

     

    //radMultiPageInstrFileVwr.PageViews[6].Controls.Add(LoadControl("~/Instr/InstrCommentControl.ascx"));

     

     

     

     

     

    if (Convert.ToInt32(Request.QueryString["Tab"]) == ApplicationConstants.PRODUCT_TAB)

     

    {

    tabStrpInstrFiles.SelectedIndex = 4;

    radPageViewProducts.Selected =

    true;

     

    }

     

    this._presenter.OnViewLoaded();

     

     

    this.Master.CheckSessionTimeout();

     

    }

    Thanks and Regards
    V.Balamurali

  2. Paul
    Admin
    Paul avatar
    4281 posts

    Posted 01 Oct 2009 Link to this post

    Hi Balamurali,

    Please refer to our TabStrip / Load on Demand RadPageView example that shows the needed approach.

    Greetings,
    Paul
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top