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
Load .ascx page from database into LoadControl as a string
Re: Load .ascx page from database into LoadControl as a string
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
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?
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?
Nick Cole
http://www.ethofy.com
http://www.ethofy.com
Re: Load .ascx page from database into LoadControl as a string
Nice tip nickc!
Re: Load .ascx page from database into LoadControl as a string
Serialize the control first and then store it in the database.
http://www.4guysfromrolla.com/webtech/012302-1.shtml
http://www.4guysfromrolla.com/webtech/012302-1.shtml
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com