You are here:   Home
Register   |  Login

Programmer Newsletter

Minimize

Master Programmer

Minimize

Find articles on computer software, programming, ASP.net, Sql server, databases, C#, websites, Internet, Windows, Outlook macros.

Programming Articles

Minimize
09

When controls are initialized on an asp.net page, the Page object may not be available. You get an error message that says: Object reference not set.

After initialization, during the Load phase, the Page object is available.

What if you need the Page object during the initialization phase, such as in the CreateChildControls method?

Derive a class from the Page class. During the PreInit event, save a reference to the Page object in HttpContext.Current.Items.

You can then retrieve the reference whenever you need it, even during initialization of controls.

public static string http_context_page = "web_page";
HttpContext.Current.Items.Add(http_context_page, this); // Save
Page page = (Page)HttpContext.Current.Items[http_context_webpage]; // Retrieve

Posted in: Asp.net

Post Rating

Comments

There are currently no comments, be the first to post one.

Post Comment

Name (required)

Email (required)

Website

Programmer Newsletter

Minimize

Subscribe to the Internet Handholding newsletter

MAKE YOUR PC SUPER FAST Discover 5 Shockingly Simple Techniques That Will Make Any Old Computer Run At Top Speed.

Drive Traffic to Your Website with Article Underground. Increase Your Visitors and Your Profits.

HOW TO HYPNOTIZE ANYONE AT WILL! Amazing Secrets to Hypnotize Anyone, Anywhere, at Any Time for Whatever Reason.



Programming Bookmark

Minimize

Share/Bookmark Bookmark and Share