65.9K
CodeProject is changing. Read more.
Home

ASP Control: On Page_Load event, markup control is null

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Aug 18, 2011

CPOL
viewsIcon

17681

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:

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

MediaGalleryPostThumbnail.ascx is the implemented custom control here.