2

This might be a silly question, but i have a confusion.
Every .aspx page inherits System.Web.UI.Page and Page class has some properties Like, IsPostBack, IsValid,IsCrossPagePostBack and many more... to access these property we write Page.IsPostBack or IsPostBack.
Now, Question is , are these property static , if not then how these are accessible in the .apsx file, i have tried to test with a class but not succeeded.

    public class clsDemo:System.Web.UI.Page
    {
    }  
Mohammad Arshad Alam
  • 9,694
  • 6
  • 38
  • 61

1 Answers1

1

Page class derives from TemplateControl class;

public class Page : TemplateControl, IHttpHandler

and TemplateControl class derives from abstract Control class;

public abstract class TemplateControl : Control, ...

In Control class which Page class derives from there is a virtual property named as Page;

    // Summary:
    //     Gets a reference to the System.Web.UI.Page instance that contains the server
    //     control.
    //
    public virtual Page Page { get; set; }

In the Page class there are properties like IsPostBack, IsValid etc;

    // Summary:
    //     Gets a value that indicates whether the page is being rendered for the first
    //     time or is being loaded in response to a postback.
    //        
    public bool IsPostBack { get; }

Thus,

Since the aspx page derives from Page class, it also inherits TemplateControl and Control classes. In Control class there is a public property named as Page thus you can access Page property in your class. And Page class has public properties like IsPostback and IsValid etc., so you can use these properties from Page property.

public class Test : Page
{
    public Test()
    {
        bool test = this.IsCallback;
    }
}
daryal
  • 14,643
  • 4
  • 38
  • 54