Storing ascx in database

跟風遠走 提交于 2020-01-04 08:15:22

问题


I would like to store the ascx control code into a database. Then rather then load the control from a filepath location, I would like to retrieve it from the database and load it into the UserControl. The UserControl.LoadControl only has two overload options. Without saving the control from a database to a temporary file and then load from the temporary file, is it possible do this direct from the database?


回答1:


Can you use ParseControl instead? Link to MSDN.

The method accepts a string that is then compiled on the fly as a Control object.

You could load your control markup from the database and then hand it off to ParseControl to get an instance of your control back.

Hope this helps!




回答2:


The only problem is that the ParseControl does not cause compilation, so if there are any Codes in your ascx, they will not get executed.

So far the only option for me has been to write the ascx to file (either permanently or temporarily) and then use LoadControl method to load the ascx.



来源:https://stackoverflow.com/questions/7072313/storing-ascx-in-database

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