473,327 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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 3491

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
0
by: George Durzi | last post by:
I have a C# in my web application called BasePage. It inherits from System.Web.UI.Page. I'm using page inheritance in my web app so all my pages have an identical look and feel by inheriting from...
3
by: Robert Walter | last post by:
I want to user the Page method LoadControl inside the Global.asax.cs but when I instantiate a page and try it I get the following error... System.NullReferenceException: Object reference not set...
10
by: Umut Tezduyar | last post by:
It seems, it is caching it. The following code is an example for it. How can avoid from this. override void OnLoad (sender and eventargs) { Control control = this.LoadControl (path);...
4
by: Christopher | last post by:
I am trying to load a UserControl which inherits from one of our customer classes which in turn inherits from UserControl. We use Page.LoadControl() from within our ASP.NET pages to load these...
8
by: Sam Kuehn | last post by:
How do I accomplish the fallowing (is it even possible). Say I write a UserControl "MyControl.ascx". Now I use LoadControl("MyControl.ascx"). But I really want MyControl to require parameters in...
6
by: John | last post by:
Hi all, I am using dynamic user controls within my web app and these controls are loaded into placeholders via the LoadControl method. My problem is this: I have usercontrolA loaded into a...
2
by: Keith Patrick | last post by:
Maybe my expectations are just too low because I haven't read much documentation on this method, but basically, I am trying to load a user control dynamically without using a virtual path (I have...
1
by: Joe | last post by:
Hello All, I have a class that inherits from System.Web.UI.Page. In it I call the Page.LoadControl. I am having trouble with the virtual path that the LoadControl method accepts as its...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.