usercontrols + code-behind

Discussion in 'ASP .Net Web Controls' started by wh, Feb 13, 2004.

  1. wh

    wh Guest

    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.
     
    wh, Feb 13, 2004
    #1
    1. Advertising

  2. Your post went unanswered. Have you resolved this issue?

    --
    Regards,
    Alvin Bruney [ASP.NET MVP]
    Got tidbits? Get it here...
    http://tinyurl.com/3he3b
    "wh" <> wrote in message
    news:lb5Xb.11676$q%...
    > 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.
    >
    >
     
    Alvin Bruney [MVP], Mar 2, 2004
    #2
    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. Ben Miller [msft]

    Re: Code Behind vs. no code behind: error

    Ben Miller [msft], Jun 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    648
    Alphonse Giambrone
    Jun 28, 2003
  2. wh

    usercontrols + code-behind

    wh, Feb 13, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    353
    Alvin Bruney [MVP]
    Mar 2, 2004
  3. Mark Fitzpatrick
    Replies:
    2
    Views:
    3,834
    =?Utf-8?B?QWxleCBNYWdoZW4=?=
    Apr 24, 2004
  4. Daniel Manes

    Code-Behind Pain in the Behind!

    Daniel Manes, Jun 10, 2005, in forum: ASP .Net
    Replies:
    11
    Views:
    709
  5. John

    Non-code behind to code behind

    John, Feb 19, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    532
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Feb 19, 2007
Loading...

Share This Page