How can I find the name of (default.aspx ) current page or web control in the code behind?
I want to write a superclass that uses this name.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You mean that you want to find the original filename of the object that is currently executed? I.e., from inside a control MyControl you want to retrieve
MyControlOnDisk.ascx? In general, this information is lost upon compiling, and moreover, many pages and controls are built on partial classes and the filenames they’re from are compiled into a single assembly.For a page, you can use the following, but only if the page is not internally redirected, is not instantiated as a class from another page, it is not a master page and you’re not inside a static method:
In the case of a control, it is generally not possible as far as I know (it is compiled away), but perhaps someone can shed some light on this.
I assume you mean to write a subclass? If you write a superclass you just create a virtual method and have it implemented in your subclass (the page). If you mean to create a subclass, you can take the classname of the page, which looks like this:
and use it like this to derive from it: