Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello,

Can anyone tell me how it is possible to use Page class properties and method without instantiating an Page Class object?

For Example -
C#
public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack) //How do you use property of Page before you create "Page" class object
        {

        }

    }
}
Posted

1 solution

You don't have to.
Remember, your Login class is derived from Page, so everything Page contains, your class contains.
And the Page class contains a property "Page" which is preset for you when the base class constructor is executed - which happens before your class constructor, as you probably know!
 
Share this answer
 
Comments
Nelek 15-Mar-14 17:44pm    
1-Countered
user413004 17-Mar-14 2:10am    
Can you explain this in more details?

I just wanted to get my basics right.
OriginalGriff 17-Mar-14 12:25pm    
Yes, in effect.
It's not really complicated, but it has to do with the page lifecycle: basically every time the client talks to the server, the whole page is created, and the Load event is called, then any button click event and so on. Because your page is derived from the Page class, that happens with your page as part of that.

Have a look here:
http://msdn.microsoft.com/en-us/library/ms178472.aspx
which covers the events.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900