[英]access parent page constant variable from user control page
我们可以从child(User control)页面加载事件中访问在页面加载上方声明的父页面const变量吗?
public const int ConstantCollection = 3;
Yes you can, if your constant is public
. 是的,如果您的常量是
public
,则可以。
<NameOfThePageClass>.<YourConstantName>
Constant variables behave like static variables, with the exception that you can't change them. 常量变量的行为类似于静态变量,但不能更改它们。
Since your asp.Net page is a class after all, you can access your constant as you would access it if it was in a standard class. 由于您的asp.Net页毕竟是一个类,因此可以访问常量,就像访问标准类中的常量一样。
Example: 例:
public class MyWebPage
{
public const string myConst = "test";
}
to access it: 访问它:
public void MyMethodSomewhereInAClass()
{
this.text = MyWebPage.myConst;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.