Injecting html

  • Thread starter Thread starter Simon Harvey
  • Start date Start date
S

Simon Harvey

Hi All

I am making a particular asp.net page using the codebehind method. What I
need to do is write out html in the code behind into a specific place in the
page. Somewhat like the way Servlets work.

I have a couple of questions I hope someone can help with:

1. Can I output html by doing something like Response.out.write("<b>"); and
is this the best way to do it
2. How can I add some sort of placeholder for where I want to inject the
html?

I should also add that I don't want to use the other asp.net mechanism that
doesnt use code behinds

Thanks everyone.

Simon
 
the best way i have found to do this is to use a Label. set the text
property to whatever you want the html to be on that part of the page.

lblExample.Text = "<b>";

<asp:Label ID="lblExample" runat="server"/>
 
Placeholder is the best bet. You can then output literal controls
(LiteralControl class) and attach them to the placeholder. I like the panel,
which creates a <span> in HTML.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
You can use something like this:

<=%BuildHTML%>
</body>

Where BuildHTML is defined in your codebehind as:

Protected Function BuildHTML() as String
 
Back
Top