且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

LoadControl VS构建ASP.Net控制

更新时间:2023-12-06 10:19:58

在动态加载的用户控件,重要的是要确保标准ASP.NET页面事件管线启动并正常进展。当您使用new运算符来创建用户控件的实例,该用户控件没有正确添加到ASP.NET的事件系统。如果事件(初始化,加载,preRender等),以不火,那么你的控制将永远不会正常工作。这就是为什么必须使用LoadControl,因为这将确保您的用户控件的实例正确创建并连接到ASP.NET。

When dynamically loading a user control, it is important to ensure that the standard ASP.NET page event pipeline is initiated and progresses normally. When you use the new operator to create an instance of a user control, that user control is not properly added to ASP.NET's event system. If the events (Init, Load, PreRender, etc.) to not fire, then your control will never function properly. That is why it is necessary to use LoadControl, as that will make sure that the instance of your user control is created properly and attached to ASP.NET.