LoadControl VirtualPath question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • George Durzi

    #1

    LoadControl VirtualPath question

    I have a C# in my web application called BasePage. It inherits from
    System.Web.UI.P age. I'm using page inheritance in my web app so all my pages
    have an identical look and feel by inheriting from BasePage.

    In my BasePage class, I have an OnInit method defined as shown:

    protected override void OnInit(System.E ventArgs e)
    {
    this.Controls.A ddAt(0, LoadControl("_h eader.ascx"));
    base.OnInit(e);
    }

    _header.ascx, and _footer.ascx are in the root of the virtual directory. And
    if I had a page called default.aspx which inherited from BasePage,
    everything is cool.

    Let's say however, that I have a directory called misc, and I have a page
    called misc.aspx within that directory that inherits BasePage. When I browse
    it, I get an error.

    The error occurs at this.Controls.A ddAt(0, LoadControl("_h eader.ascx"));
    because the app obviously can't find _header.ascx at
    c:\inetpub\wwwr oot\LRWIntranet \misc\_header.a scx

    But if I change the OnInit function in BasePage trying to have it always
    know to look for _header.ascx in the root, my app breaks.
    For example:
    this.Controls.A ddAt(0, LoadControl("/_header.ascx")) ;
    I get The virtual path '/_header.ascx' maps to another application, which is
    not allowed. when I browse to http://localhost/lrwintranet/misc/misc/aspx

    I always want the call to LoadControl to look in the root of the virtual
    directory, but I can't get it to do that, any idea?


Working...