views:

52

answers:

2

Hi All,

I'm not sure if it is possible to render an asp.net control from a string. The string contains fragments of html code and I've tried rendering that string to a div tag with runat="server" set, asp panel contain, asp lalbel control and asp literal control. All of them doesn't render the asp control in that text to an actual control, it just come up as a string. I've tried adding <% %> around them and it appears it doesn't like it.

Thanks in advance.

+2  A: 

You may need to instantiate your control in the code behind (e.g. new Label()) and then add that control to a placeholder control that you put on your page.

Paddy
Thanks for the quick reply, I see what you mean by added the control in the code behind page, but the problem is the asp control is already embedded into the text string which is being fetched from a database. I'm not sure how to render that string out to the screen with the while i have the asp control embedded on the string.
madness800
You can't just render an asp control in that fashion - the framework renders the controls it has during the page lifecycle, all you're doing is adding a string to a control, not a server control itself. You'll either have to parse the string for the control tags or re-look at your design, and I'd vote for the latter if at all possible.
Paddy
A: 

Literal and Label do this job. Please specify some code for more understanding.

Also you may look to http://msdn.microsoft.com/en-us/library/f93yf0ee(VS.80).aspx

sashaeve
this is the string i want to render out to the screen:<div id="toplogo"><table style="width: 100%;"><tr><td style="width: 200px"><asp:Image ID="imgLogo" runat="server" ImageUrl="~/images/logo.jpg" Width="193" Height="93" AlternateText="Logo" /></td><td>Logo</td></tr></table></div>As the string above I have an asp image control within that string and I'm not exactly sure how to render that string so it shows the image on the screen instead of just render that asp control code as text but visible in view source.
madness800