aspx and ascx

P

Peter Kirk

Hi there

I am trying to write some "web user controls" which I want to include on an
aspx.

In my VS2005 solution I have a project with my aspx, and another project
with my user controls (ascxs). But I can't compile my solution because the
aspx complains that it can see the ascxs. I get an error like:

Element 'MyControl' is not a known element. This can occur if there is a
compilation error in the Web site.
File 'MyControl.ascx' was not found.

Do the ascxs have to sit in the same project as the aspx?

My aspx looks like this:

<%@ Register TagPrefix="uc" TagName="MyControl" Src="MyControl.ascx" %>

<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="ControlTest.aspx.cs"
Inherits="alphasolutions.web.control.test.ControlTest" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Test Input</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc:MyControl id="a_control" runat="server" />
</div>
</form>
</body>
</html>



Thanks,
Peter
 
J

Jeppe Jespersen

Do the ascxs have to sit in the same project as the aspx?

I'm pretty sure I read somewhere that ascx's are not "real" re-useable, but
only copy/paste re-useable.
So my answer would be yes, they do need to be in the same project.

/jespersen
Denmark
 
S

Steve C. Orr [MVP, MCSD]

Yes, they need to be in the same project. This is the only supported way to
do it, although I've heard of unsupported techniques such as using shared
virtual directories for the user controls.
For high quality reusability you should create custom controls, not user
controls.
Here's more info:
http://SteveOrr.net/faq/UserCustom.aspx
 
P

Peter Kirk

Jeppe Jespersen said:
I'm pretty sure I read somewhere that ascx's are not "real" re-useable,
but only copy/paste re-useable.
So my answer would be yes, they do need to be in the same project.

/jespersen
Denmark

Tak, Jeppe!

mvh,
Peter (Danmark).
 
P

Peter Kirk

Steve C. Orr said:
Yes, they need to be in the same project. This is the only supported way
to do it, although I've heard of unsupported techniques such as using
shared virtual directories for the user controls.
For high quality reusability you should create custom controls, not user
controls.
Here's more info:
http://SteveOrr.net/faq/UserCustom.aspx

Great, thanks for the info. I think I'll stick with the user-controls for
the moment, and live with the "restriction".

Thanks,
Peter
 

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,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top