aspx and ascx

Discussion in 'ASP .Net Web Controls' started by Peter Kirk, Jun 20, 2006.

  1. Peter Kirk

    Peter Kirk Guest

    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
     
    Peter Kirk, Jun 20, 2006
    #1
    1. Advertising

  2. >
    > 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
     
    Jeppe Jespersen, Jun 20, 2006
    #2
    1. Advertising

  3. 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

    --
    I hope this helps,
    Steve C. Orr, MCSD, MVP
    http://SteveOrr.net



    "Peter Kirk" <> wrote in message
    news:%...
    > 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
    >
     
    Steve C. Orr [MVP, MCSD], Jun 21, 2006
    #3
  4. Peter Kirk

    Peter Kirk Guest

    "Jeppe Jespersen" <jdj curlythingie jdj dot dk> skrev i en meddelelse
    news:%...
    > >
    >> 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


    Tak, Jeppe!

    mvh,
    Peter (Danmark).
     
    Peter Kirk, Jun 21, 2006
    #4
  5. Peter Kirk

    Peter Kirk Guest

    "Steve C. Orr [MVP, MCSD]" <> skrev i en meddelelse
    news:...
    > 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
    >
    > --
    > I hope this helps,
    > Steve C. Orr, MCSD, MVP
    > http://SteveOrr.net


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

    Thanks,
    Peter
     
    Peter Kirk, Jun 21, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Quentin
    Replies:
    1
    Views:
    521
    Quentin
    Jul 29, 2003
  2. Jason Shohet
    Replies:
    1
    Views:
    517
    Kevin Spencer
    Nov 10, 2003
  3. Holger (David) Wagner
    Replies:
    2
    Views:
    1,981
    Holger (David) Wagner
    Jul 3, 2004
  4. Joe
    Replies:
    1
    Views:
    413
    Jeffrey Tan[MSFT]
    Feb 16, 2004
  5. Replies:
    2
    Views:
    565
Loading...

Share This Page