开发者

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

开发者 https://www.devze.com 2023-03-13 10:24 出处:网络
I have a text file containing the following HTML tags: <table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"500\">

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)


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)


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
0

精彩评论

暂无评论...
验证码 换一张
取 消