我如何才能找到在ASP.NET当前页面的(文件)的名字吗? [英] How can I find the (file) name of the current page in ASP.NET?

查看:128
本文介绍了我如何才能找到在ASP.NET当前页面的(文件)的名字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能找到(Default.aspx的)当前页面或网页控制在后面的代码的名字吗?

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.

推荐答案

您的意思是说,你想找到当前执行对象的原始文件名?即,从控制内MyControl要检索 MyControlOnDisk.ascx ?在一般情况下,这个信息是在编译丢失,此外,许多网页和控制建立在局部类和它们从被编译成一个单一的组件是文件名。

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:

string currentPageFileName = new FileInfo(this.Request.Url.LocalPath).Name;

在控制的情况下,一般是不可能的,据我所知,(它编译距离),但也许有人能阐明这一些轻。

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:

// current page
public partial class MyLovelyPage : System.Web.UI.UserControl

和使用它像这样从中得出:

and use it like this to derive from it:

public partial class NewDerivedPage : MyLovelyPage

这篇关于我如何才能找到在ASP.NET当前页面的(文件)的名字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆