4

I've got two files in the same directory, an ascx file and an ascx.cs file with a C# class defined inside of it.

This is the code in my .ascx file

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Test.ascx.cs" 
Inherits="SITE.UI.Controls.Test" %>

And this is the code in Test.ascx.cs:

using System;
using System.Web.UI;

namespace SITE.UI.Controls
{
    public partial class Test : System.Web.UI.UserControl
    {


    }
}

However whenever I try and build the site I always get this error:

Error 1 Could not load type 'SITE.UI.Controls.Test'

I'm sure I must be doing something obviously wrong but after over an hour of thrashing I'm getting nowhere . . .

4

3 に答える 3

3

Go into the Web Project properties -> Build settings and change the Output Path to bin\

If that don't work, check this post. Here are a lot of solutions for this problem.

Let me know it when it's fixed or not :)

于 2012-07-10T09:19:47.113 に答える
2

I will tell about my case and what worked for me. I have a project that worked fine. For no known reason, it got compile/build error. I have User Controls in a Controls folder. After dealing with compile error for web handlers, I got a new set of errors for each User control in my Controls folder. I tried many things include delete the designer file (and create another one empty), the error I got was Could not load type 'Name.Of.Class' (In directive line #1 <%@ Control %>).

My solution was: I have added Another parallel control with the name OriginalControlName2.ascx. Then copied all content from @.ascx to @2.ascx and the same for ascx.cs. So far so good, no compile error for new page/control. Then exclude the original file, and change the name of the #2 file to the name of the original. Error list got down to zero.

With all my experience, I don't know what was the issue, but I got the fix.

**************UPDATE***************

every time when I finish a set of files, it continued to the others. I find out that the directive <%@ Page/WebHandler/Control/ %> had a CodeBehind attribute. When I changed it to CodeFile, the Error went off the list. It is much shorter than adding new file and move all code.

Good luck.

于 2015-03-07T21:17:18.227 に答える
0

Just wanted to add what worked for me when I was getting the same error. I did an iisreset which resolved the issue.

于 2015-09-03T12:11:32.457 に答える