views:

63

answers:

3

I was wondering if it was possible to load a asp.net control (.ascx) that doesn't reside on the file system?

Like say a string variable?

+1  A: 

System.Reflection.Emit

Assembly.Load(byte[])

No designer for you if you do this though.

Joshua
+3  A: 

Not a string varible but you can load it from resources or zip file, but you have to have full trust. Google for VirtualPathProvider.

epitka
of course, if you can source web content from a zip file using a VPP, you can also source web content from *anything* - any sort of backing store. A database (I think sharepoint does this), or... even... a string. The key is the VPP. I don't know of a VPP that works with "strings" or in-memory representations, but the VPP model is not complicated and it should be straightforward to build one.
Cheeso
Actually, there is one more way, loading it directly from the variable but you cannot have any expressions in the page <$= or <%# etc. You would create a class and then load markup using Page.ParseControl(markup). If you need example send me an email.
epitka
@Cheeso: You are right, I was just pointing that he cannot do it straight from varible, but has to use provider for it. The only issue I have with providers is that they require full trust, so no application in shared hosting.
epitka
A: 

You could try this:

string controlString = //read or build it
Control control = this.Page.TemplateControl.ParseControl(controlString);

More information is available here:

http://msdn.microsoft.com/en-us/library/kz3ffe28.aspx

Mike