Using Page keyword in asp.net
Is it necessary to use the Page keywo开发者_开发问答rd in asp.net? For example, are there differences setting the Title or control if the page IsPostBack?
If we don't use the Page keyword will there be a problem in the future?
Because the code appears to do the same thing:
Page.Title = "Test";
is equal to
Title = "Test";
ASP.NET pages and controls ultimately inherit from Control
, which has a property named Page
, which refers to the current page the control is on, or, in the case of pages, the page themselves. As far as I know, there's no difference between calling Page.Title
and Title
from your pages, because they both refer to the same object. The question then, becomes a matter of preference and convention. I would pick one way and stick with it for readability.
Reference:
- http://msdn.microsoft.com/en-us/library/system.web.ui.page.aspx
- http://msdn.microsoft.com/en-us/library/system.web.ui.control.page.aspx
精彩评论