Getting path/directory of aspx file from within user control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need some help with this.

I have two files
page.aspx: A page that a user calls

uc.ascx: A user control that page.aspx uses. The ascx file has HTML used
for a site background which would display one of two images. If page.aspx is
in the root directory, the displayed image has no text. If page.aspx is
anywhere but the root directory, the displayed image has "Home" on it. I
already created these two images, so I simply have to call the right image
URL from the user control.

Unfortunately, I don't know how to go about writing this part of the code.
FileInfo and DirectoryInfo classes require a path, but how do I tell these
classes to check the current page's location (not uc.ascx's location)? I
would like only one uc.ascx file.

Thanks.
 
Quick and Dirty or maybe not.

I would create a property in the uc.ascx class.
Pass a value from the .aspx file (Page Load event would work) to the
uc.ascx class. Indicating which image to use.
In the set{} of that property you could then assign the correct Image
URL to an Image control for example
 
Kevin,
Thanks for the response.

I just found that within the control file (uc.ascx), I can use
Page.TemplateSourceDirectory to get a directory name. I can check the string
and compare it to my root directory string. I have to go test this.

I think this might be more "efficient" than letting the page send a value to
the user control, but if the above fails, I can try your idea.
 
Back
Top