?
Solved

what is the difference loading Web user control loading on page?

Posted on 2011-05-03
1
Medium Priority
?
156 Views
Last Modified: 2012-05-11
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 = "Ilçe giriniz...";
    kontrol2.PostaKodu = "90000";

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

Open in new window

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)

0
Comment
Question by:programmerist
1 Comment
 
LVL 11

Accepted Solution

by:
Kelvin McDaniel earned 2000 total points
ID: 35688294
If the two techniques I prefer something similar to the first one. However article is VERY dated and there may already be something that supports your intent in the v2.0 or v4.0 Frameworks.

Of the two options the first one gives you a lot more future flexibility and expected behavior. The second one, while being much more succinct, is very limited and might eventually lead to problems with ViewState, especially if you're going to be accessing the Control's properties at runtime via events.

The first question is really, "do you need to load the control programmatically?", which is only necessary if you're going to be changing the type of control you're loading. Otherwise I see very little benefit to using either technique. I prefer to use the @Register declarative in the HTML markup... This way you don't have to play funny tricks with the ViewState Unless you are wiring up special behaviors.

As far as passing in parameters, simply add Properties to the Control; once you've registered the control on the page you'll get the benefit of IntelliSense too. Or, you can simply set the Properties as attributes in the markup.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question