简体   繁体   English

在C#中渲染htm标签

[英]Rendering htm tag in C#

Hi and thanks in advance for reading. 嗨,谢谢您的阅读。

Recently, I upgraded my application from .net2 to .net 4.5. 最近,我将应用程序从.net2升级到.net 4.5。 Everything works fine except the top htm control 除了顶级的htm控件之外,一切都正常

"<html runat="server" id="pageHtm">

Running the appplication, I get this weird parser error: 运行应用程序,我得到这个奇怪的解析器错误:

The base class includes the field 'pageHtml', but its type (System.Web.UI.HtmlControls.HtmlElement) is not compatible with the type of control (System.Web.UI.HtmlControls.HtmlGenericControl).

After a lot of tries, I got that this is a known bug and the solution is a patch by Microsoft. 经过大量尝试,我发现这是一个已知的错误,解决方案是Microsoft的补丁程序。 However, the problem still exists even after installing the patch. 但是,即使安装了补丁,问题仍然存在。

To resolve this problem, follow these steps: 要解决此问题,请按照下列步骤操作:

  1. open the PageName.aspx.designer.cs file. 打开PageName.aspx.designer.cs文件。

Note The placeholder PageName represents the name of the Web page on which you encounter the problem. 注意占位符PageName代表您在其上遇到问题的网页的名称。

2.Locate the entries for the tbody , thead , and tfoot tags. 2.找到tbodytheadtfoot标签的条目。

3.Change the entries to map these tags to the new classes. 3.更改条目以将这些标签映射到新类。 For example, make the following 例如,进行以下操作

changes. 变化。

Old entry 旧条目

protected global::System.Web.UI.HtmlControls.HtmlGenericControl tbodyname;

New entry 新条目

protected global::System.Web.UI.HtmlControls.HtmlTableBodySection tbodyname;

Save the PageName.aspx.designer.cs file. 保存PageName.aspx.designer.cs文件。

To automatically resolve this problem by using the Visual Studio designer, follow these steps: 若要通过使用Visual Studio设计器自动解决此问题,请按照下列步骤操作:

1.In Visual Studio open the PageName.aspx file. 1.在Visual Studio中,打开PageName.aspx文件。

Note The placeholder PageName represents the name of the Web page on which you encounter the problem. 注意占位符PageName代表您在其上遇到问题的网页的名称。

2.In the Source window, locate the 2.在“源”窗口中,找到 and tags, and then select all entries in the range that includes these tags. 标签,然后选择包含这些标签的范围内的所有条目。

3.On the Edit menu, click Cut . 3.在“ 编辑”菜单上,单击“ 剪切” This operation removes the corresponding entries from the PageName.aspx.designer.cs file. 此操作从PageName.aspx.designer.cs文件中删除相应的条目。

Keep the cursor in the same location. 将光标保持在同一位置。

4.On the Edit menu, click Paste . 4.在“ 编辑”菜单上,单击“ 粘贴” This operation adds the entries that inherit the new classes back to the PageName.aspx.designer.cs file. 此操作将继承新类的条目添加回PageName.aspx.designer.cs文件。

Save the PageName.aspx file. 保存PageName.aspx文件。

Answer above is a general solution but your case 上面的答案是一个通用的解决方案,但您的情况

open your designer file of your page in solution explorer and change all of 在解决方案资源管理器中打开页面的设计器文件,然后更改所有

System.Web.UI.HtmlControls.HtmlElement

to

System.Web.UI.HtmlControls.HtmlGenericControl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM