1

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 setting the following attributes: runat="server", asp panel contain, asp label control and asp literal control.

These attributes do not render the control in that text to an actual control. The result remains as a string.

I've also tried adding <% %> around the attributes but this is not accepted.

Thanks in advance.

1

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
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.
0

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

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.