Register User Control for ALL pages in a site

Discussion in 'ASP .Net Web Controls' started by David Bowey, Mar 9, 2005.

  1. David Bowey

    David Bowey Guest

    Hi There!

    Typically I can register a user control for a page using...

    <%@ Register TagPrefix="myControls" Src="controls/test.ascx" TagName="test"
    %>

    But how do I "register" a user control so that it can be assessable from ALL
    pages in the current website? Are there any configuration settings in the
    web.config file that I set for this?

    Creating a Custom Control (with compiled DLL) is not an option for this
    project. However, I have the option to create my own base class but I have
    no idea how to include a User Control from that base class. I know I can use
    "LoadControl" function but I need the design-time support.

    For example, a user should be able to set control's properties in an ASPX
    page like this...

    <myControl:test id="test1" runat="server"
    myProperty1="test"
    myProperty2="test"></myControl:test>

    without having to declare "Register" directive at the top of the page. So
    "LoadControl" is no go.

    Any pointers will be much appreciated!

    Dave
    David Bowey, Mar 9, 2005
    #1
    1. Advertising

  2. David Bowey

    quaester Guest

    Yes! you can do that by adding the following in your web.config.
    (or even machine.config if you want to apply to the entire machine, but not
    wise to do so)

    <configuration>
    <system.web>
    <pages>
    <controls>
    <add TagPrefix="myControls" Src="controls/test.ascx"
    TagName="test"/>
    </controls>
    </pages>
    </system.web>
    </configuration>


    "David Bowey" wrote:

    > Hi There!
    >
    > Typically I can register a user control for a page using...
    >
    > <%@ Register TagPrefix="myControls" Src="controls/test.ascx" TagName="test"
    > %>
    >
    > But how do I "register" a user control so that it can be assessable from ALL
    > pages in the current website? Are there any configuration settings in the
    > web.config file that I set for this?
    >
    > Creating a Custom Control (with compiled DLL) is not an option for this
    > project. However, I have the option to create my own base class but I have
    > no idea how to include a User Control from that base class. I know I can use
    > "LoadControl" function but I need the design-time support.
    >
    > For example, a user should be able to set control's properties in an ASPX
    > page like this...
    >
    > <myControl:test id="test1" runat="server"
    > myProperty1="test"
    > myProperty2="test"></myControl:test>
    >
    > without having to declare "Register" directive at the top of the page. So
    > "LoadControl" is no go.
    >
    > Any pointers will be much appreciated!
    >
    > Dave
    >
    >
    >
    quaester, Mar 9, 2005
    #2
    1. Advertising

  3. David Bowey

    David Bowey Guest

    Thanks for the reply! However, a few problems...

    I added the following code to web.config file...

    <configuration>
    <system.web>
    <pages>
    <controls>
    <add TagPrefix="myControls" Src="controls/test.ascx"
    TagName="test"/>
    </controls>
    </pages>
    </system.web>
    </configuration>

    However, I'm getting the following error...

    Parser Error Message: Child nodes are not allowed.

    at the line where "<controls>" is wirtten...

    Any ideas? Is it because I'm using ASP.NET 1.1?

    Thanks again!
    Dave

    "quaester" <> wrote in message
    news:...
    > Yes! you can do that by adding the following in your web.config.
    > (or even machine.config if you want to apply to the entire machine, but
    > not
    > wise to do so)
    >
    > <configuration>
    > <system.web>
    > <pages>
    > <controls>
    > <add TagPrefix="myControls" Src="controls/test.ascx"
    > TagName="test"/>
    > </controls>
    > </pages>
    > </system.web>
    > </configuration>
    >
    >
    > "David Bowey" wrote:
    >
    >> Hi There!
    >>
    >> Typically I can register a user control for a page using...
    >>
    >> <%@ Register TagPrefix="myControls" Src="controls/test.ascx"
    >> TagName="test"
    >> %>
    >>
    >> But how do I "register" a user control so that it can be assessable from
    >> ALL
    >> pages in the current website? Are there any configuration settings in the
    >> web.config file that I set for this?
    >>
    >> Creating a Custom Control (with compiled DLL) is not an option for this
    >> project. However, I have the option to create my own base class but I
    >> have
    >> no idea how to include a User Control from that base class. I know I can
    >> use
    >> "LoadControl" function but I need the design-time support.
    >>
    >> For example, a user should be able to set control's properties in an ASPX
    >> page like this...
    >>
    >> <myControl:test id="test1" runat="server"
    >> myProperty1="test"
    >> myProperty2="test"></myControl:test>
    >>
    >> without having to declare "Register" directive at the top of the page. So
    >> "LoadControl" is no go.
    >>
    >> Any pointers will be much appreciated!
    >>
    >> Dave
    >>
    >>
    >>
    David Bowey, Mar 9, 2005
    #3
  4. David Bowey

    quaester Guest

    Did you add in to the wrong part of your web.config?
    in your web.config there should have the <configuration><system.web>, you'll
    just need to add in the hierarchy.
    Sorry to say, I'm using .net 2.0, I've looked up the msdn and it doesn't
    seems to appear for 1.1..

    "David Bowey" wrote:

    > Thanks for the reply! However, a few problems...
    >
    > I added the following code to web.config file...
    >
    > <configuration>
    > <system.web>
    > <pages>
    > <controls>
    > <add TagPrefix="myControls" Src="controls/test.ascx"
    > TagName="test"/>
    > </controls>
    > </pages>
    > </system.web>
    > </configuration>
    >
    > However, I'm getting the following error...
    >
    > Parser Error Message: Child nodes are not allowed.
    >
    > at the line where "<controls>" is wirtten...
    >
    > Any ideas? Is it because I'm using ASP.NET 1.1?
    >
    > Thanks again!
    > Dave
    >
    > "quaester" <> wrote in message
    > news:...
    > > Yes! you can do that by adding the following in your web.config.
    > > (or even machine.config if you want to apply to the entire machine, but
    > > not
    > > wise to do so)
    > >
    > > <configuration>
    > > <system.web>
    > > <pages>
    > > <controls>
    > > <add TagPrefix="myControls" Src="controls/test.ascx"
    > > TagName="test"/>
    > > </controls>
    > > </pages>
    > > </system.web>
    > > </configuration>
    > >
    > >
    > > "David Bowey" wrote:
    > >
    > >> Hi There!
    > >>
    > >> Typically I can register a user control for a page using...
    > >>
    > >> <%@ Register TagPrefix="myControls" Src="controls/test.ascx"
    > >> TagName="test"
    > >> %>
    > >>
    > >> But how do I "register" a user control so that it can be assessable from
    > >> ALL
    > >> pages in the current website? Are there any configuration settings in the
    > >> web.config file that I set for this?
    > >>
    > >> Creating a Custom Control (with compiled DLL) is not an option for this
    > >> project. However, I have the option to create my own base class but I
    > >> have
    > >> no idea how to include a User Control from that base class. I know I can
    > >> use
    > >> "LoadControl" function but I need the design-time support.
    > >>
    > >> For example, a user should be able to set control's properties in an ASPX
    > >> page like this...
    > >>
    > >> <myControl:test id="test1" runat="server"
    > >> myProperty1="test"
    > >> myProperty2="test"></myControl:test>
    > >>
    > >> without having to declare "Register" directive at the top of the page. So
    > >> "LoadControl" is no go.
    > >>
    > >> Any pointers will be much appreciated!
    > >>
    > >> Dave
    > >>
    > >>
    > >>

    >
    >
    >
    quaester, Mar 9, 2005
    #4
    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. ATJaguarX

    @ Register User Control Tag Problem

    ATJaguarX, Oct 6, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    5,458
    ATJaguarX
    Oct 7, 2004
  2. Nathan Sokalski
    Replies:
    5
    Views:
    1,006
    Gaurav Vaish \(www.Edujini-Labs.com\)
    Jan 10, 2007
  3. David Bowey

    Register User Control for ALL pages in a site

    David Bowey, Mar 9, 2005, in forum: ASP .Net Building Controls
    Replies:
    3
    Views:
    125
    quaester
    Mar 9, 2005
  4. Nathan Sokalski
    Replies:
    4
    Views:
    284
    Nathan Sokalski
    Dec 21, 2006
  5. Nathan Sokalski
    Replies:
    4
    Views:
    320
    Nathan Sokalski
    Dec 21, 2006
Loading...

Share This Page