programatically get ascx file name

J

jeremy.stitt

Can anyone tell me how to get a string of the file name for an ascx
file?

On an aspx file, Request.Servervariables["PATH_INFO"] will return the
path of the aspx. But if I add that same code to an ascx user control
included in the aspx file, I still get the aspx file name.

How can I get the path info of the current ascx user control?
 
A

Andrew Backer

There may be a more elegant way, but this is the only one that I have
tried to get working :

Run this inside the control itself

string file = TemplateSourceDirectory + "/" +
GetType().ToString().Replace("ASP.","").Replace("_ascx",".ascx");

GetType will return something ugly like : ASP.MyHeader_ascx, which is
what all those Replace()s get rid of. This appears to work regardless
of the class name, so it should work in some case like this :

<%Register TagPrefix = "b" TagName="UnRelated" Src"MyControla.ascx"%>
MyControl.ascx
MyControl.ascx.cs
"public abstract class MyControlRules : UserControl"

You will still get "MyControl.ascx" as a return value, not the actual
class name which might be different from the file name (though it
shouldn't be).

Hope this helps,
Andrew Backer
 

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

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,134
Latest member
Lou6777736
Top