470,594 Members | 1,531 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,594 developers. It's quick & easy.

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

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.
Nov 18 '05 #1
2 3286

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" <JA*@2.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
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.

Nov 18 '05 #2
Thank you - that solved the problem.
"Oleg Ogurok" <ol**@ogurok.com.ihatespammers.ireallydo.co> wrote in message
news:10*************@corp.supernews.com...

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" <JA*@2.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
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.


Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

28 posts views Thread by Jon Davis | last post: by
reply views Thread by George Durzi | last post: by
3 posts views Thread by Robert Walter | last post: by
4 posts views Thread by Christopher | last post: by
8 posts views Thread by Sam Kuehn | last post: by
6 posts views Thread by John | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.