LoadControl() method throws virtual path error when attempting to load user control from subfolder.

Discussion in 'ASP .Net' started by Jeremy, Jun 24, 2004.

  1. Jeremy

    Jeremy Guest

    Everything in my app worked fine - then I moved some user controls to a
    subfolder named \ControlTemplates that physically exists directly under the
    site root.

    Then, at runtime when these lines attempts to load a user control from that
    subdirectory:
    string templateFileName = @"/ControlTemplates/Template01.ascx";
    Control templateControl = LoadControl(templateFileName);

    The application throws an error with the following message:
    The virtual path '/ControlTemplates/Template01.ascx' maps to another
    application, which is not allowed.

    How can I load user controls that are physically stored in a subfolder under
    the site root?

    Thanks.
    Jeremy, Jun 24, 2004
    #1
    1. Advertising

  2. Jeremy

    Oleg Ogurok Guest

    Try adding a tilda (~)
    string templateFileName = @"~/ControlTemplates/Template01.ascx";

    or you can get the root of your app this way:

    string templateFileName = Request.ApplicationRoot +
    @"/ControlTemplates/Template01.ascx";

    -Oleg.


    "Jeremy" <> wrote in message
    news:%...
    > Everything in my app worked fine - then I moved some user controls to a
    > subfolder named \ControlTemplates that physically exists directly under

    the
    > site root.
    >
    > Then, at runtime when these lines attempts to load a user control from

    that
    > subdirectory:
    > string templateFileName = @"/ControlTemplates/Template01.ascx";
    > Control templateControl = LoadControl(templateFileName);
    >
    > The application throws an error with the following message:
    > The virtual path '/ControlTemplates/Template01.ascx' maps to

    another
    > application, which is not allowed.
    >
    > How can I load user controls that are physically stored in a subfolder

    under
    > the site root?
    >
    > Thanks.
    >
    >
    Oleg Ogurok, Jun 24, 2004
    #2
    1. Advertising

  3. Jeremy

    Jeremy Guest

    Thank you - that solved the problem.


    "Oleg Ogurok" <> wrote in message
    news:...
    >
    > Try adding a tilda (~)
    > string templateFileName = @"~/ControlTemplates/Template01.ascx";
    >
    > or you can get the root of your app this way:
    >
    > string templateFileName = Request.ApplicationRoot +
    > @"/ControlTemplates/Template01.ascx";
    >
    > -Oleg.
    >
    >
    > "Jeremy" <> wrote in message
    > news:%...
    > > Everything in my app worked fine - then I moved some user controls to a
    > > subfolder named \ControlTemplates that physically exists directly under

    > the
    > > site root.
    > >
    > > Then, at runtime when these lines attempts to load a user control from

    > that
    > > subdirectory:
    > > string templateFileName = @"/ControlTemplates/Template01.ascx";
    > > Control templateControl = LoadControl(templateFileName);
    > >
    > > The application throws an error with the following message:
    > > The virtual path '/ControlTemplates/Template01.ascx' maps to

    > another
    > > application, which is not allowed.
    > >
    > > How can I load user controls that are physically stored in a subfolder

    > under
    > > the site root?
    > >
    > > Thanks.
    > >
    > >

    >
    >
    Jeremy, Jun 24, 2004
    #3
    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. jlopes
    Replies:
    7
    Views:
    407
    jlopes
    Nov 19, 2004
  2. =?Utf-8?B?SmVmZiBCZWVt?=

    physical path to virtual path under virtual directory

    =?Utf-8?B?SmVmZiBCZWVt?=, Aug 1, 2007, in forum: ASP .Net
    Replies:
    4
    Views:
    1,026
    Eliyahu Goldin
    Aug 1, 2007
  3. Rory Plaire

    When does LoadControl really load the control?

    Rory Plaire, Aug 12, 2003, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    151
    Rory Plaire
    Aug 12, 2003
  4. Stephane

    Error when Load control dynamically with LoadControl

    Stephane, Mar 30, 2008, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    809
    Stephane
    Mar 30, 2008
  5. J055

    User controls and LoadControl method

    J055, Oct 3, 2006, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    141
    Luke Zhang [MSFT]
    Oct 5, 2006
Loading...

Share This Page