Click here to Skip to main content
15,886,110 members
Articles / Web Development / ASP.NET
Tip/Trick

ASP Control: On Page_Load event, markup control is null

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
21 Aug 2011CPOL 17.5K   2  
This situation is quite tricky and happens when you add a custom control to some page.

During page load, all child controls receive the OnLoad event. When you try to access controls defined in the control's markup in the OnLoad method override, all markup controls are NULL.


To solve this mysterious problem, you must register the custom control's tag using its relative URL path like:


ASP.NET
<%@ Register Src="~/CustomControls/MediaGalleryPostThumbnail.ascx" 
    TagName="MediaGalleryPostThumbnail" TagPrefix="CC" %>

MediaGalleryPostThumbnail.ascx is the implemented custom control here.

License

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


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --