saam
saam

Reputation: 491

"Type or namespace name could not be found" in UserControl

I want to do the following in a UserControl:

foreach(Control c in this.Controls)
{
   if(c is CheckBox)
   {
       // Do stuff here
   }
}

But I get the the error:

Error 1 The type or namespace name 'Control' could not be found (are you missing a using directive or an assembly reference?)
Error 2 The type or namespace name 'CheckBox' could not be found (are you missing a using directive or an assembly reference?)

Thankyou for the guidance.

Upvotes: 1

Views: 4263

Answers (4)

Alex
Alex

Reputation: 8937

You should add either System.Windows.Forms, or System.Web.UI.WebControls, or System.Windows.Controls depending on what technology you use

Upvotes: 3

Soner Gönül
Soner Gönül

Reputation: 98868

You need to add System.Windows.Forms namespace which includes System.Windows.Forms.dll for Control class.

Also you need to add System.Web.UI.WebControls namespace which includes System.Web.dll for Checkbox class.

Like;

using System.Windows.Forms;
using System.Web.UI.WebControls;

Upvotes: 2

KF2
KF2

Reputation: 10171

you need to add System.Windows.Forms.dll.

It's located in System.Windows.Forms.dll in the System.Windows.Forms namespace.

Upvotes: 1

Andrei
Andrei

Reputation: 56726

You forgot to include either System.Web.UI.WebControls or System.Windows.Forms (depending on the type of the app you are developing) with using directive.

Upvotes: 8

Related Questions