flavour404
flavour404

Reputation: 6312

The type of namespace name 'Control' could not be found (are you missing a using directive or assembly reference?)

Trying to set up an extension method in .Net 3.0 using generics and I get an error message, details above on the line:

foreach(Control childControl in parent.Controls)

Am I missing a using directive or assembly reference?

Thanks

What I am trying to do is set this up (below) as an extender function:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;

namespace System.Runtime.CompilerServices
{
    public static class ControlHelper
    {
    public static T FindControl<T>(this Control parent, string controlName) where T : Control
    {
        T found = parent.FindControl(controlName) as T;
        if (found != null)
            return found;
        foreach (Control childControl in parent.Controls)
        {
            found = childControl.FindControl(controlName) as T;
            if (found != null)
                break;
        }
        return found;
    }
}
}

I am missing a reference to the system.core.dll... its driving me nuts!

Upvotes: 2

Views: 19202

Answers (2)

user20492
user20492

Reputation: 1

  1. Add the System.web.dll to refrence in solution explorer at right side.
  2. Add the namespace - System.Web.UI.WebControls; at the top of your web page.
  3. then you can create the web control by the coding itself.

Upvotes: 0

Sam Harwell
Sam Harwell

Reputation: 99859

Choose the one for the technology you're using:

Windows Forms:

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

WPF: (probably not this one, because there's no relevant Controls property in the WPF classes)

It's located PresentationFramework.dll in the System.Windows.Controls namespace.

Web Controls:

It's located System.Web.dll in the System.Web.UI namespace.

Upvotes: 9

Related Questions