Insert HTML dynamicaly

  • Thread starter Thread starter Carlos Cruz
  • Start date Start date
C

Carlos Cruz

Hi,

I've donne some web development in PHP and I'm trying to change to ASP.NET.
I'm used to insert HTML code dynamically on a page. Does ASP.NET works this
way too ?

For example:

Supposing I want to create dynamically an HTML Table with a link on each
row. In PHP I insert <?PHP Function that returns the HTML Code(); ?>.

How can this be donne in ASP.NET?

Thanks in advane,
CC
 
ASP.NET offers different paradigm, better forget how you did this and that
in PHP, if you want to become good ASP.NET developer.
 
Carlos said:
Hi,

I've donne some web development in PHP and I'm trying to change to
ASP.NET. I'm used to insert HTML code dynamically on a page. Does
ASP.NET works this way too ?

For example:

Supposing I want to create dynamically an HTML Table with a link on
each row. In PHP I insert <?PHP Function that returns the HTML
Code(); ?>.

How can this be donne in ASP.NET?

Typically, in ASP.NET this would be done by dropping a Datagrid
control on the page, and by adding a HyperlinkColumn to it.
Then you bind the datagrid dynamically with the DataBind() method.

Although it is still possible to insert HTML code on a page in the way that
PHP does it (with render blocks), ASP.NET is more object oriented than PHP.
That's why the code is better kept away from the HTML, and all the
rendering is done through controls.
 
Take a look at the ASP.NET Literal control
(System.Web.UI.WebControls.Literal).

You can declaratively place the literal control in the HTML in your ASPX
page, then in your code-behind logic you simply set the text property of the
control to whatever HTML you want to be rendered in the browser.

For example - your HTML in the ASPX page:
<table>
<tr>
<td><asp:Literal id="MyLiteralControl" runat="server"></asp:Literal></td>
</tr>
</table>

Then in the code-behind page (in the .ASPX.cs):
System.Web.UI.WebControls.Literal MyLiteralControl; // this line declares
the control in C#

MyLiteralControl.Text = strHTMLToRenderInBrowser; // this line provides the
literal control with the HTML to render in the locatoin of the Literal
control (in the <TD> in the example above).

HTH

-Jeff
 
Back
Top