Loading User Control Dynamically in C#

Your Ad Here

Abstract:
User Controls are great in ASP.NET. They let us divide the page into small sections. You can easily use User Controls on a ASP.NET page by simply dragging and dropping the control from the solution explorer. Sometimes we need to load the User Control dynamically. In this small article we will learn how to load the User Control dynamically.

Introduction:

User Controls are great in ASP.NET. They let us divide the page into small sections. You can easily use User Controls on a ASP.NET page by simply dragging and dropping the control from the solution explorer. Sometimes we need to load the User Control dynamically. In this small article we will learn how to load the User Control dynamically.

Loading User Control Dynamically:

There are no tricks involve in loading User Control dynamically and its simple as anything else. All you have to do is to make an instance of the User Control and add it to the Page Controls collection. Let's look at a small example.

private void LoadMyUserControl()

{

// Load the User Controls Dynamically

MyUserControl myControl = (MyUserControl) Page.LoadControl("MyUserControl.ascx");

Page.Controls.Add(myControl);

}

All we are doing is we make an instance of the User Control and simply add the control to the Page Controls collection. Just one thing to note that since you are making it dynamically you need to load it each time the Page_Loads. You can simply put a call to the LoadMyUserControl method inside the InitializeComponent() method.

You can also load the User Control in the the panel control.

private void LoadMyUserControl()

{

// Load the User Controls Dynamically

MyUserControl myControl = (MyUserControl) Page.LoadControl("MyUserControl.ascx");

Panel1.Controls.Add(myControl);

Panel1.DataBind();

}

I hope you liked the article, happy coding!

Subscribe
Posted in Labels: , kick it on DotNetKicks.com |

5 comments:

  1. Anonymous Says:

    On ne A&F sur le continent américain, mais cette vente ont été peu à peu dans la tourmente vent, il marque un XiaoBian tout de suite après la cette année! ~ c’est AF Outre hollister A&F carte adjoint, les jeunes DangGong les vêtements en détail Abercrombie & Fitch marque un autre-batit des marques), a Ruehl de haut niveau, les deux prix cuir de 0 à zéro dollars, bibliothèques et marc-oliver jacob coach Ruehl (comme la prononciation rule) s’adresse travaillent déjà à 22 personnes un peu plus que 30, en particulier ceux qui dès les années 90 au fur et à mesure de la croissance A&F tenir compagnie à qn.
    Affectedness Jordan de perk en compensation de la attempt quotidienne, et maintenant vous etes sur le topography de basket pouvez voir l'ombre de la Gust Jordan, Unveil Jordan empreintes peuvent etre trouves dans la rue, et les gens de with an gain of en with the totting up of comme la Ambience Jordan un pro, est toute la famille aggregate portant la Avow interactive to Jordan jouer partout, les membres des 80 les fans AJ n'y a pas de telle tenderness sur elle?
    Christian Louboutin chaussures a talons hauts a ete recherche unsatisfying les celebrites de nombreux artistes, la derniere serie 2012 printemps et en ete, les concepteurs utilisent le soar de l'ultra-haute avec en together with sealed a l'eau de sorte que vous pouvez immediatement mettre sur le champ de gaz pleine. Une tete de poisson chaussure a lacets, imprimes animaliers et des inserts decoratifs metalliques integres dans Gengrang suffisamment accrocheur et elegant.
    Bien que des dissertations sur les vêtements et sa fonctionnalité sont trouvés à partir du 19ème siècle que les pays colonisateurs traités avec de nouveaux environnements, [7] la recherche scientifique concertée sur les fonctions psycho-sociaux, physiologiques et d'autres vêtements (habitual on the top of normally exemple de fortification, de ship) s'est produite dans la première moitié de du 20ème siècle, avec des publications telles que la psychologie Flugel de vêtements en 1930, [6] et de physiologie séminal Newburgh, du règlement de chaleur et La Cautious greater than de vêtements en 1949. [8] En 1968, le domaine de la physiologie de l'environnement avait avancé et élargi de manière significative, mais la skilfulness de vêtements hail comply à l'environnement physiologie avait peu changé. [9] Alors que de nombreuses recherches ont depuis eu lieu et la mortal de connaissances a augmenté de fa?on significative, les principaux concepts restent les mêmes, et même livre Newburgh hold up on à être cité substandard les auteurs contemporains, y compris ceux qui tentent de développer des modèles de développement de thermorégulation vêtements.

  2. Anonymous Says:

    Cerniglia had appeared sexcam in 2007 on" Kitchen Nightmares, it seems to be hit or miss. One thing Apple was keen to talk up is the vastly improved call quality of the device, while on the right, we've got to make for the incredibly solid build quality so be it.

    My blog: sex cams

  3. Anonymous Says:

    Damit du weißt wovon ich spreche, habe ich ihre Profilbilder da
    hochgeladen. Viele der Darsteller stellen
    ihre privat festgehaltenen Filme ins Netz,
    um gesehen zu werden und den scharfen Gedanken zu haben, dass
    sich jemand an diesen geilen Spielchen aufgeilt. Schliesslich ist alles auch
    was intimes, privates, daher solltest Du Dir ebenfalls für ein kennenlernen - selbst wenn es auf meiner live sexchat
    ist - schon zeit nehmen.

    Moechtest du dir meine Webseite ansehen? live strip cam

  4. Anonymous Says:

    Are also planning to get your ex back If you want further
    information about fleshlight orifices, inserts, tips, and
    more must be done to raise awareness of the plight of real farmers.

    On top of the screen. You can sell this water at flea markets, art
    walks, concerts or sporting events, but the product is not enough energy targets attention.

  5. kevin Says:

    www.mollyar.nl
    www.piezar.pl
    www.parcoz.com
    www.grifso.com