Find articles on computer software, programming, ASP.net, Sql server, databases, C#, websites, Internet, Windows, Outlook macros.
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
By Andrew Weitzen, Bronze Inc. (c) 2010
Bronze is the publisher of several online Internet journals including: InternetHandholding.com, DomainNames.gs, DotNetNuke.bz, Programmer.bz, Software.vg, WebHosting.vg
Name (required)
Email (required)
Website
Notify me of followup comments via e-mail
AWeber Email List Marketing Test Drive
Use email marketing to convert targeted subscribers to customers. Let the system sell itself for you!