将HTML合并到现有的asp.net页中 [英] Merge HTML into an existing asp.net page

查看:131
本文介绍了将HTML合并到现有的asp.net页中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个单独的类中有一个返回字符串的方法.实际上,该字符串中包含HTML(Head,body等).我正在后面的代码中的一种方法中检索此字符串,并且我希望将此html合并到当前现有的HTML和ASP.Net(.aspx文件)中,并在当前页中显示返回的字符串(HTML)上的内容创建一个新的div或其他一些好的方法.如果有人对此有任何想法,请提供帮助.如果需要进一步了解,请询问其他信息.

谢谢

Anil

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

推荐答案

如果页面是整页,我假设您只想提取正文内容.可能最简单的方法是解析<body> </body>标记之间的内容.


OP希望获得有关如何完成此操作的信息.好的,一种方法是使用XML从HTML中选择主体节点(假设它在格式正确的XML文档中),然后选择InnerText.然后,您可以将该内容写到文字控件中.

可以这样读取:
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.


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:
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]


<%@ 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>







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;


谢谢大家的帮助,它已经解决了!
Thanks guys for the help, its resolved!


这篇关于将HTML合并到现有的asp.net页中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆