usercontrols + code-behind

W

wh

After spent a good half day looking for a solution I'm no further finding an
answer so I'd appreciate any ideas as to how this can be done.

I have developed a user control that resides in a .ascx file with the
associated .ascx.cs file holding the code. Each .aspx page that uses this
control has appropriate <% Register %> directives at the top of the page:

<%@ Register tagprefix="mytag" tagname="mycontrol"
src="usercontrols/mycontrol.ascx" %>

The code-behind file (.aspx.cs) for each page has a reference to the class
(MyControl) that has been defined in the code-behind (.ascx.cs) file for the
control.

protected MyControl myCtl;

Currently, the project I'm working on is built using VS.NET and is thus
compiled as a single .DLL which sits in the BIN subdirectory. This works
FINE.

The problem comes when I remove the .DLL that VS.NET builds and instead use
a 'SRC' attribute in the <%@ PAGE %> directive for each page. This allows me
to make changes to the code sitting in the code-behind file while at the
same time ensuring that the .NET Framework compiles any modifications on the
fly. This has worked well in the past. However, since adding the control to
the project, I now get an error whenever the .NET Framework compiles each
..aspx page containing the definition for the control:

protected MyControl myCtl;

I can't remember the exact error, but it's complaing that the 'MyControl'
type is not recognised. I know for a fact that it's in the same namespace as
the class in the code behind file for the .aspx page. It seems that .NET is
compiling the .ASPX page before the .ASCX page, and as a consequence knows
nothing about the MyControl class.

I have tried using the <%@ Assembly %> and <%@ Reference %> directives in
the .aspx file without any success.

Thanks,
Wayne.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top