.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Tab Control - load user controls in tab dynamically when tab is selected

Posted By:      Posted Date: October 22, 2010    Points: 0   Category :ASP.Net

I have searched the forum and I cant seem to find the answer to my question, although I have tried some of the hints I have found with no luck....

Can someone show me a working sample (with source code) of a page with a TabContainer and several tabs, with each tab having a user control, but the controls are not added/initialized/shown until the appropriate tab is shown/clicked?

Something like this forum's "Write a New Post" page, where the tabs load after I click on them, and an animated picture displays to show that its loading.

The solution needs to add user controls to the page, not just html into a dynamic populate extender.

I have one user control per tab, and is linked (ala master-child relationship) to the page using a property. My user controls perform long-running web service queries, and I dont want to waste database/computing resources loading content into a tab that the user will never look at.   Right now, all tabs load their content when the page loads, even though the first tab is only shown.

As mentioned above, sample code for the page (.aspx and .cs) and the user control (.ascx and .cs) would really help.


View Complete Post

More Related Resource Links

Dynamically load user control without postback


Hi all,

I need urgent help. (c#coding)

In my base page, I have a dropdownlist control which loads different usercontrols on selectedindexchanged event.

While loading these usercontrols, my page postbacks all the page. I used updatepanel but again same problem.

Is there any way to load controls without postback? I Really need help as soon as possible.

Here is my code:

protected void Page_Init(object sender, EventArgs e)
        if (Session["control"] != null)
            string c = Session["control"].ToString();
            if (c == "1")
                iuc = (IlkogretimUC)LoadControl("~/Controls/Ilkogretim.ascx");
                dl.SelectedValue = Session["control"].ToString();
            else if (c == "2")
                luc = (LiseUC)LoadControl("~/Controls/LiseUC.ascx");
                dl.SelectedValue = Session["control"].ToString();
            else if (c == "3")
                youc = (YuksekokulUC)LoadControl("~/Controls/Yuksekokul.ascx");

Persist data in a dynamically populated ListBox in a user control


Hi All,

I am trying to persist data in a dynamically populated ListBox in a user control. Here are the details

I have a user control which contains a a listBox and button. On Page_Load of user control I am populating the ListBox control with some values. On Click of button, I am trying to fetch the values which I have selected in ListBox. Though this seems very simple and straight forward I am unable to fetch values.

My Page_Load Function

void Page_Load(object sender, EventArgs e)










My Click Function

Protected Void Button1_Click(object sender, EventArgs e)


       string strValue = listBox.SelectedValue



I have placed brake point at Page_Load and on click function, I am seeing that the moment the breakpoin

User Controls and Control Extenders


Two separate questions, but sufficiently intertwined that I'm going to try the two together....

Firstly - User Controls and Behaviours

I have a User Control which contains a few visual controls.  I am attaching some behaviours by using GetScriptDescriptors and am passing some JavaScript to the browser using GetScriptReferences.  That is all rock solid and working well.  However, when developing, I did discover that I couldn't attach the behaviours to the User Control itself - not surprising as rendering a User Control does not create a DOM element which represents the actual control.  So, I have attached my behaviours to a "random" TextBox within the User Control. 

So - first question, is there a better way to do that?  For example, should I always be rendering a SPAN as an element to surround the control?  Not sure what that would do to the robustness of the rendering.  What is the right way to attach a behaviour to a User Control.

Secondly - Accessing those same Behaviours later

Assume I have placed a User Control on the page.  That User Control exposes a Property (actually a Javascript Function of course) which does "something" to the control - for the sake of example we'll say that the function is set_Border(colour). 

How to dynamically create user controls ?



can you explain how to create user control dynamically in a web form ?When i am creating server controls of user controls are not instantiated and it is not getting initialized .when i am tyying to initialize its properties error occurs tha object instance not created .

Any suggestion ? 

Dynamically (on client side) populating data control (repeater) when dropdown item is selected

Hello!I'm currently working on a project and I want to make as much things as possible performing on client side - with as little loading as possible.The project consist of three "main" pages. On one page I use jQuery DataTable plugin which is working great. One page has tabs (using jQuery). I want to put datacontrol (repeater) on this site and when  user selects one item in dropdown, data in repeater loads on client side, without performing the action on server.I wonder if this is possible and if somebody can give me some case to help with?Thanks!I hope I was clear enough. all the best

Dynamically adding User Controls -- newbie question!

I am new to ASP.NET (coming from ColdFusion, thank goodness I'm away from that!).  And I am have THE hardest time understanding how to work with forms in ASP.NET.  Here's what I am doing:Dynamically add User Controls to a PlaceHolder based on some int value (which currently is passed in a HiddenField).Fire an event if the WebControls inside of the User Control change, then handle that event in the Main Page (i.e. save the input to DB)When the user clicks the "Next/Continue" button, the next controls for the next page are loaded.And I guess maybe I just can't seem to get how things work in ASP.NET, because I am really struggling with the general idea of how ASP.NET flows.  Should I be dynamically loading the controls in Page_Init, or Page_Load?  Or should I load the controls when the buttonclick event is fired?Do I have to add the axCtrl.OnDataChange += new EventHandler(HandleAxControlDataChange); line on Page_Load?  Or should I put this in When I first load the UserControl, I need to initialize some WebControls within the UserContorl.  Is there a way to know if I have loaded new user controls into my placeholder?  I can't use Page.IsPostback, because after the first page, every page is a postback from the buttonclick.Any help for this confused newbie would be GREATLY appreciated!!Here's what I have: pu

Enable/Disable controls dynamically based on User settings

In my project I have a requirement that all controls in each window shall be enabled or visible dependent on user and the admin shall be able to change is a user will be able to use or see the control. I made a very simple test application that creates a user and gives him a list (will be loaded from db in real app) of the name of the controls in the window and also his settings. Then after initializing the window I use reflection to find the controls and set their isenabled/visibility properties. This solution does the thing but I'm wondering if there is a better solution. The main issue here is that each control must be set per user and thus roles wont work appropriate and also that I need to be able to change the settings at runtime.  

Dynamically add user control with events


I'm trying to make web form with two placeholders. Firs holder contains user control witch has list of buttons, each button opens different user control to second placeholder.

I get it to show user control in second placeholder but i can't get dynamically created user controls to fire events.

So how i can dynamically create working user control with button click?

Here is how i create those controls:

 Dim toiminot As Control = LoadControl("~/kontrollit/" & field.Value)

"field" is hidden field containing filename of user control to be created.

All help is appreciated!

DataAnnotation on multiple user controls displaying on wrong control


I have a table that displays a user control on each row. The user controls are strongly typed to a viewmodel which contains DataAnnotation style validation. If one of the rows has invalid data entered (lets say the 3rd row) the data annotation validates display agains the first row/user control.

How do I get the data annotation to show against the relevant user control?

I'd post a pic to show what I mean except it will not display it!.:/

Prioritizing User Control Load



I have 2 user controls on a asp.net page.UserControl1 is placed first and then UserControl2 is placed Second.Naturally the UserControl1 loads first and then UserControl2 loads after the Usercontrol1 is loaded.

My Requirement is to place Usercontrol1 and then usercontrol2.But then Usercontrol2 should fire first and then the Usercontrol1 should be fired.I need this to be reversed since because i have to get the value from the second user control according to which the first user control would be populated.I had found that it can be done with Delegates.But since i have used Delegates Scarcely.I am still working on to get an answer.Can someone help me with this problem.



JQuery & dynamically instantiated User control



I have one problem which needs to be resolved immediately. I am using JQuery Datatable (http://www.datatables.net/).

This JQuery datatable is present in one of my webuser control named "LeftVerticalLayOut.ascx". I am dynamically instantiating Webusercontrol on click of a link button. This link button is bound with the trigger event of Update Panel control.

So clarifying once again : I have one UpdatePanel which I am triggering with Link button("lnkLoadControl") . On click on "lnkLoadControl" I am able to load Usercontrol("LeftVerticalLayOut.ascx") onto the updatepanel. Now the jquery datatable I am creating in load event of Usercontrol is getting generated.


After the datatable(having id as "example") is created, I am calling the below code in my

function loadHandler()

function BeginRequestHandler(sender, args)

function EndRequestHandler(sender, args)

Acessing controls in usercontrol in javascript function where user control hosted in webpart



1how to acess controls in usercontrol  in javascript function where user control hosted in webpart


2)How to retieve values from javscript code to server side

details as follows

StringBuilder controlString = new StringBuilder();
            controlString.Append("<p>" + CurrentPage.ToString() + "of " + TotalPages.ToString() + " </p>");
            for (int intIndex = 1; intIndex <= TotalPages; intIndex++)
                controlString.Append("<li><a hre

Not able to access child controls in user control using javascript



I have a user control "SettingsControl" containing an ajax:CollapsiblePanelExtender which in turn has a GridView (gridView) and checkBoxes. On top of GridView we have two LinkButtons "Select All" and "Clear All". I have written to enable select all and clear all functionality. Select All should select all the rows in the grid by calling the following JavaScript written on the Client .aspx file.

function SelectAll(chk)
    //get reference of GridView control
    var grid = document.getElementById('<%= SettingsControl1.FindControl("gridView").ClientID %>');
    //variable to contain the cell of the grid
    var cell;

    if (grid.rows.length > 0)
        //loop starts from 1. rows[0] points to the header.
        for (i=1; i<grid.rows.length; i++)
            //get the reference of first column
            cell = grid.rows[i].cells[0];


Group events and dynamically loaded user control


My main file is messages.aspx and i am loading a UC names message_inbox.ascx dynamically as:

SiteUserControls_Message_MessageInbox    InboxUC = Page.Load("message_inbox.ascx") as


Now in my user control ("message_inbox.ascx") i have a various events which i am combining in one group event :

 public void ForwardLinkButton_OnClick(object sender, EventArgs e)
        LinkButton thisButton = (LinkButton)sender;

User Controls : load and access properties from code behind



I created a User Control :

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="UCSousMenuPrincipal.ascx.cs"
    Inherits="view_usercontrols_UCSousMenuPrincipal" %>
<asp:DataList ID="dataListSousMenuPrincipal" runat="server" RepeatDirection="Horizontal" >
        <asp:HyperLink ID="HyperLink1" runat="server"><%# Container.DataItem %></asp:HyperLink>

to which I added a property, so I can bind the DataList :

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

public partial class view_usercontrols_UCSousMenuPrincipal : System.Web.UI.UserControl
    //Private Member    
    private object dataSource = null;
    protected void Page_Load(object sender, EventArgs e)

User controls are not being removed from the main form control




I have the following piece of code:


foreach (Control ct in this.Controls) { if (ct is uctAssignment) { ct.Hide(); ((uctAssignment)ct).CloseMe(); }

  public void CloseMe()
If I have 15 controls to be deleted, it only deletes about 4 or 5 at a time, such that I have to envlose the above foreach loop inside a for loop.

In addition, when I make a call to Control.Hide() inside a similar loop, I can observe the same behavior.

Does anyone know why is it behaving like that?

Any ideas?


Enable/Disable controls dynamically based on User settings


I need an elegant way to enable/disable controls in my WPF application at run time using an external settings file(xml file)

I know this can be done using binding with Visibility/ IsEnabled property for all the controls, but how will i do change that in run time.

I also want to know whether combining the Settings.settings file and use bindings is the way to go.

There is documentation for VS2005 but not for VS2008 related to Settings.settings file approach.

I need recommendation for this type of features in WPF apps

Any help will be highly appreciated.




ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend