1

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)

1
  • You can use a <asp:Literal /> to do something like this. Commented Jun 14, 2011 at 18:15

2 Answers 2

1

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)
Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

The problem with jquery is that those changes are made only after page is shown to the client and I want to do it before the client get the page

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.