really need to import  System.Web.UI.WebControls?

Posted on 2011-10-28
Last Modified: 2012-05-12

Just converting from to c#

Do I really need to import  System.Web.UI.WebControls on any page where i reference a control in c#?

So for instance:
TextBox txtQty = null; errors unless I have:
using System.Web.UI.WebControls;

Never needed to do that in so a bit suprised?
Question by:scm0sml
    LVL 7

    Expert Comment

    You only need to use "using-namespace" if you want to be able to avoid explicitly declaring the namespace at each reference.  I.e.:

    System.Web.UI.WebControls.TextBox txtQty = null;


    Author Comment

    Yeah I suppose my question is doesn't this get automatically in c# like it does in

    I dont need to do this in
    LVL 7

    Accepted Solution

    I'm not sure if VB does this automatically.  I'm also not positive if it MUST be done in C#, as I suppose it's possible for the compiler/interpreter to handle it automatically in certain situations (when there are no ambiguities, etc.).  The documentation certainly implies it is necessary, and I don't recall an exception.

    I suppose a fairly indicative test would be to create a namespace containing a class with a name you know is not duplicated anywhere (e.g., class "skjfekljferioudpoiudopiuf") and reference that class without the namespace qualifier from a different namespace.  If that doesn't compile, I would assume it simply is never permitted - since that seems like the simplest example.

    Author Comment

    Just seems silly to have to import references to web controls on a web page?!

    Surely that can assumed....

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    746 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

    15 Experts available now in Live!

    Get 1:1 Help Now