Page 1 of 1

Load .ascx page from database into LoadControl as a string

Posted: Thu Sep 18, 2008 11:24 am
by Odettes
Hi!

I want to store a .ascx file into the database (under productdescription) and then load it into another .ascx file using a placeholder and the LoadControl.
My problem is that I dont know how to get LoadControl to accept a string instead of a file.

If I use "ProductDescription.ascx" i can fetch the data from the correct file using "<asp:Literal ID="phCaption" runat="server" Text="Description" EnableViewState="false"></asp:Literal>", but that will not work for me cause I need the text from the database to be rendered together with the orginal .ascx page and not just inserted as regular text.

Any ideeas?

Best regards, Thomas

Re: Load .ascx page from database into LoadControl as a string

Posted: Fri Sep 19, 2008 4:33 am
by mazhar
What about loading the string data from db then creating a temporary control file in conlib from the loaded data. When you have the file then you can load the user control using that temporary file.

Re: Load .ascx page from database into LoadControl as a string

Posted: Fri Sep 19, 2008 11:27 am
by nickc
How dynamic is the loaded control?
Could the task be achieved using a common set of controls with public properties and methods and just abstract the name and properties of the control in the db?
(something like table.column="controlname,property=value, property2=value2, ..." parsed to dynamicControl[] and loaded from there)
You should be able to push markup directly to the page using Response.Write().
There are also techiques for executing code stored as text using Reflection:
http://www.codeproject.com/KB/cs/evalcscode.aspx.
The temporary control file strikes me as messy. It will never be cached. When do you clean it up?

Re: Load .ascx page from database into LoadControl as a string

Posted: Sun Sep 21, 2008 11:25 pm
by mazhar
Nice tip nickc!

Re: Load .ascx page from database into LoadControl as a string

Posted: Tue Sep 23, 2008 3:06 pm
by AbleMods
Serialize the control first and then store it in the database.

http://www.4guysfromrolla.com/webtech/012302-1.shtml