Question

i try to load some user control on my Default.aspx page selecting dropdown control. i searched some data from net i 've learn 2 methods there is first one :

http://blah.winsmarts.com/2006/05/20/loadcontrol-a-usercontrol--and-pass-in-constructor-parameters.aspx

Second one:

http://www.csharpnedir.com/articles/read/?filter=&author=&cat=aspx&id=689&title=Kullan%C4%B1c%C4%B1%20Web%20Kontrollerini%20Daha%20Etkin%20Kullanmak

Secand one is simple:


protected void Page_Init(object sender, EventArgs e)
{
    AdresBilgisi kontrol1=(AdresBilgisi)LoadControl("AdresBilgisi.ascx");
    AdresBilgisi kontrol2 = (AdresBilgisi)LoadControl("AdresBilgisi2.ascx");

    kontrol1.Ilce = "İlçe giriniz...";
    kontrol2.PostaKodu = "90000";

    phKontroller.Controls.Add(kontrol1); 
    phKontroller.Controls.Add(kontrol2);
}

which one do you prefer to loadASCx control to page? And Why? please give some detail pros and cons of 2 method(first and second)

Was it helpful?

Solution

Your second approach is the preferred one. Because you have more control of the UI and you can see the UI layout of your desired location where you put it on the page.

Regarding the first approach; it can be used unless there is some special need. e.g. If you want to load a user control at runtime depending on some situation/condition.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top