Click here to Skip to main content
15,911,848 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

I want to add
within td in asp.net design using c#.net code

for example this is my table

test.html file
<div>
<table>
<tr>
<td>
some text here....
</td>
</tr>
</table>
</div>


test.aspx file

<body>
<table>
<tr>
<td>
Heading
</td>
</tr>
<tr>
<td>
here i want insert
from test.html file.
</td>
</tr>
<table>
</body>
Posted
Comments
Jephunneh Malazarte 18-Jan-12 5:28am    
will it throw an exception if you just simply insert div inside td?
CodePrakash 18-Jan-12 5:28am    
Hello All,

I want to add div
within td in asp.net design using c#.net code

for example this is my table

test.html file
<div>
<table>
<tr>
<td>
some text here....
</td>
</tr>
</table>
</div>


test.aspx file

<body>
<table>
<tr>
<td>
Heading
</td>
</tr>
<tr>
<td>
here i want insert
from test.html file div tag.
</td>
</tr>
<table>
</body>

1 solution

Just do as follows -

In design page add one literal control -

XML
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Literal ID="htmlbody" runat="server"></asp:Literal>
    </div>
    </form>
</body>


Then in .cs page -

protected void Page_Load(object sender, EventArgs e)
        {
            StreamReader sr;
            string html;
            sr = File.OpenText(Server.MapPath("FileName.html"));
            html = sr.ReadToEnd();
            sr.Close();

            Regex start = new Regex(@"[\s\S]*<body[^<]*>",RegexOptions.IgnoreCase);
            html = start.Replace(html, "");
            Regex end = new Regex(@"</body[\s\S]*", RegexOptions.IgnoreCase);
            html = end.Replace(html, "");
            htmlbody.Text = html;
        }


It will add the html file contents to the aspx page.
 
Share this answer
 
Comments
Sorry I forgot.
You need to add two namespaces -
using System.Text.RegularExpressions - for RegexOptions
and
using System.IO - for StreamReader
CodePrakash 18-Jan-12 6:02am    
Thankyou vary much sir...
No problem.. Anytime.......

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900