baaroz
baaroz

Reputation: 51

Adding HTML tag to div in ASP.NET (VB)

I have a text file containing the following HTML tags:

<table border="0" cellspacing="2" cellpadding="2" width="500">
<tbody>
<tr>
<td>some text</td>

<td>some text</td></tr></tbody></table>

I want to be able to load these HTML tags into <div runat=server id=div1>

Any idea on how to do it with ASP.NET? (VB code is preferred)

Upvotes: 1

Views: 5563

Answers (2)

jaltiere
jaltiere

Reputation: 1118

I probably wouldn't use .NET code to do all of this. I would use jQuery to call either a service or page method that loads the contents of the text file. You could return this through a jQuery asynchronous call and then set the innerHTML property of the div with the result.

edit

If you really wanted to do it on the server side, you could do something like this:

<div id="divTest" runat="server">

</div>


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        divTest.InnerHtml = System.IO.File.ReadAllText(fileName)
End Sub

Upvotes: 1

danyolgiax
danyolgiax

Reputation: 13116

I don't know if there is a better way but you can try this code:

Dim l As New Literal()
l.Text = "<table border=""0"" cellspacing=""2"" cellpadding=""2"" width=""500""><tbody><tr><td>some text</td><td>some text</td></tr></tbody></table>"

div1.Controls.Add(l)

Upvotes: 1

Related Questions