[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

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

Hi,

Just converting from vb.net 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 vb.net so a bit suprised?
0
scm0sml
Asked:
scm0sml
  • 2
  • 2
1 Solution
 
Bill NolanCommented:
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;

...See http://msdn.microsoft.com/en-us/library/aa664766(v=vs.71).aspx
0
 
scm0smlAuthor Commented:
Yeah I suppose my question is doesn't this get automatically in c# like it does in vb.net...

I dont need to do this in vb.net?
0
 
Bill NolanCommented:
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.
0
 
scm0smlAuthor Commented:
Just seems silly to have to import references to web controls on a web page?!

Surely that can assumed....
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.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now