Load .ascx page from database into LoadControl as a string

Store UI, layout, design, look and feel; Discussion on the customer facing pages of your online store. Cascading Style Sheets, Themes, Scriptlets, NVelocity and the components in the ConLib directory.
Post Reply
Odettes
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 102
Joined: Wed Apr 02, 2008 11:00 am
Location: Stockholm, Sweden
Contact:

Load .ascx page from database into LoadControl as a string

Post by Odettes » Thu Sep 18, 2008 11:24 am

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
Sincerely,
Thomas Berglund

https://traileronline.se
AbleCommerce Gold R11 Custom

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

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

Post by mazhar » Fri Sep 19, 2008 4:33 am

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.

User avatar
nickc
Captain (CAPT)
Captain (CAPT)
Posts: 276
Joined: Thu Nov 29, 2007 3:48 pm

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

Post by nickc » Fri Sep 19, 2008 11:27 am

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?

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

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

Post by mazhar » Sun Sep 21, 2008 11:25 pm

Nice tip nickc!

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

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

Post by AbleMods » Tue Sep 23, 2008 3:06 pm

Serialize the control first and then store it in the database.

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

Post Reply