您的位置:首页 > 产品设计 > UI/UE

Using themed css files requires a header control on the page. (e.g. <head runat=“server” />)

2012-03-02 11:13 591 查看
由于项目需要需要将XML字符串显示在浏览器中,具有可收缩的“+”和“-”,通过一段时间的测试,一开始使用Webbrowser,在WPF中的Webbrowser只能Navigate文件才可以显示,如果使用Winform中使用Webbrowser,则需要引用WindowsFormsIntegration和System.Windows.Forms,在WPF中将Winform的Webbrowser放入WindowsFormsIntegration中的WindowsFormsHost里面就行了,但是Winform的Webbrowser也只能用Navigate来定位文件,和shdocvw.dll中的Webbrowser接口一样,但是Winform中的Webbrowser还有DocumentText和DocumentStream,但是给这两个属性赋值后,XML会被解析成文本,最后在网上发现可以使用以下代码实现
Response.Charset = "utf-8";
Response.ContentType = "text/xml";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
Response.Write(XML);//要传入的字符串

而以上代码要正确运行,前台Aspx页面只能留下最顶上面的一句代码,其他的Html什么的都得删除,因为XML自己要作为根节点,例如Aspx页面如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RequestMessagePage.aspx.cs" Inherits="MyNameSpace.RequestMessagePage" %>

但是项目中又在Web.config中使用了 <pages theme="Default" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />

导致所有页面要应用Default中定义的所有样式,由于以上页面没有Header,导致“Using themed css files requires a header control on the page. (e.g. <head runat=“server” />)”异常的出现。在网上搜索了下使用 EnableTheming="false" StylesheetTheme="",但是仍然没有效果。

最后通过在页面文件中添加如下代码来禁止该显示XML页面应用样式终于成功了

protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
this.Theme = null;
}


最后一点本项目是在一个页面中嵌入这个显示XML的页面,通过iframe来承载XML页面,通过Session来传递需要的值来完成的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐