The page Y.ascx cannot use the user control X.ascx

佐手、 提交于 2019-12-10 10:33:20

问题


I recently got the following error in my web application.

The page 'ControlName.ascx' cannot use the user control 'OtherControl.ascx', because it is registered in web.config and lives in the same directory as the page.

Whilst I was able to fix the error by moving the control and registering it in the page I'm curious as to why this raises an error.

This is apparently by design as design as described here (3/4 down in yellow block) but my question is why? What problem might you face by registering the control in the Web.Config and placing it the same directory?


回答1:


Maybe it is a matter of dynamic compilation. By default the "batch" attribute of the "compilation" element in your web.config is true. Something like this :

<compilation defaultLanguage="c#" debug="false" batch="true" targetFramework="4.0" />

With batch="true", whenever a control has to be compiled in a directory, the server compiles all controls (everything?) in its directory.

I would say that web.config declared controls are not compiled the same way as other controls (in another dll, another directory ?) So, mixing web.config declared controls and other controls in the same directory, some referencing the others would result in duplicate compilation and dll conflicts.



来源:https://stackoverflow.com/questions/10211635/the-page-y-ascx-cannot-use-the-user-control-x-ascx

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