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
    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?

    Jeremy, Jun 24, 2004
    1. Advertisements

  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 +

    Oleg Ogurok, Jun 24, 2004
    1. Advertisements

  3. Jeremy

    Jeremy Guest

    Thank you - that solved the problem.

    Jeremy, Jun 24, 2004
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.