econner
econner

Reputation: 727

Storing ascx in database

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?

Upvotes: 2

Views: 367

Answers (2)

sam360
sam360

Reputation: 1131

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.

Upvotes: 0

David Hoerster
David Hoerster

Reputation: 28701

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!

Upvotes: 3

Related Questions