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

Posted on 2011-05-03
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 :

Second one:

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";


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)

Question by:programmerist
    1 Comment
    LVL 11

    Accepted Solution

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on could not pull conte…
    In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now