Click here to Skip to main content
16,016,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a method in a separate class which returns a string. This string actually has a HTML in it (Head, body, etc). I am retrieving this string in one of the method in my code behind and I want this html to merge into the current existing HTML and ASP.Net (.aspx file) and display the contents on the returned string (HTML) in the current page creating a new div or some other good method. If some one has any idea related to this, please help. Ask for any further information in case you need to get a clear understanding.

Thanks

Anil
Posted

If the page is a full page, I assume you want to just extract the body content. Probably the simplest way to do this would be to just parse the content out between the <body> </body> tags.

[Edit]
The OP wanted information on how to accomplish this. Well, one way would be to use XML to select the body node from the HTML (assuming it's in a well formed XML document), and select the InnerText. You could then write this content out into a literal control.

This could be read in like:
C#
XmlDocument document = new XmlDocument();
document.Load(...); // This is where you'd load the XHTML in.
var node = document.DocumentElement.SelectSingleNode("/html/body");
string text = node.InnerText;

// Now, populate the ASP.NET literal control.
litContent.Text = text;
[/Edit]
 
Share this answer
 
v2
Comments
Sandeep Mewara 30-Nov-10 15:13pm    
Comment from OP:
Yes you are right, can you elaborate the parsing with a snippet and how would I display it into the existing page?
XML
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="CodeProjectWeb.WebForm1"
    ValidateRequest="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <% Response.Write(s);%>
    </form>
</body>
</html>



C#
public partial class WebForm1 : System.Web.UI.Page
    {
        protected string s;
        protected void Page_Load(object sender, EventArgs e)
        {
            s = "<input value=\"some value\">";
        }
        protected void btnClick_Click(object sender, EventArgs e)
        {
        }
    }
}



Good luck;
 
Share this answer
 
Thanks guys for the help, its resolved!
 
Share this answer
 

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