问题
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