ASP.NET User Control instance is null when referenced on Page_Load on page code behind

故事扮演 提交于 2019-12-04 06:50:42

You can probably access your user control from the Page_PreRender event.

You can find more documentation about the page life cycle in asp.net here.

Mark Whitfeld

I had the same issue, and it turned out that I was registering my custom control incorrectly.

Correct Definition:

<%@ Register Src="PeriodControl.ascx" TagName="PeriodControl" TagPrefix="ucs" %>

Incorrect Definition:

<%@ Register TagPrefix="ucs" Namespace="MyWebsite" Assembly="MyWebsite" %>

The only difference was to reference the ascx file directly instead of the control in the assembly. Go figure!?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!