首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过代码隐藏导致错误类型(System.Web.UI.HtmlControls.HtmlElement)向html标记添加属性是不兼容的。

通过代码隐藏导致错误类型(System.Web.UI.HtmlControls.HtmlElement)向html标记添加属性是不兼容的。
EN

Stack Overflow用户
提问于 2013-11-18 23:31:03
回答 1查看 3.8K关注 0票数 5

当我试图向我的主页中的html标记添加一个属性时:

代码语言:javascript
复制
<!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" id="primtag" runat="server">

就像后面的代码一样:

代码语言:javascript
复制
prmimaryhtml_tag.Attributes.Add("lang", "en")

我知道这个错误:

代码语言:javascript
复制
Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

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

Source Error: 


Line 4:  
Line 5:  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Line 6:  <html xmlns="http://www.w3.org/1999/xhtml" id="primtag" runat="server">
Line 7:  <head id="Head1" runat="server">
Line 8:      <title></title>

Source File: /main.master    Line: 6 

我还检查了main.master.designer.vb,它包含以下一行:

代码语言:javascript
复制
Protected WithEvents primtag As Global.System.Web.UI.HtmlControls.HtmlElement

现在,最奇怪的是:这段代码在我的本地机器上正确工作,但在我的生产服务器上却不正确。我也不知道是什么导致了这种不同的行为。

我还看了这篇文章:set pages main html tag in c#

当我的情况如下时,更新

main.master.designer.vb

代码语言:javascript
复制
 Protected WithEvents primtag As Global.System.Web.UI.HtmlControls.HtmlElement

main.master.aspx

代码语言:javascript
复制
<html xmlns="http://www.w3.org/1999/xhtml" ID="primtag" runat="server">

main.master.aspx.vb

这一行评论如下:

代码语言:javascript
复制
'primtag.Attributes.Add

我得到:

代码语言:javascript
复制
Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

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

Source Error: 


Line 4:  
Line 5:  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Line 6:  <html xmlns="http://www.w3.org/1999/xhtml" ID="primtag" runat="server">
Line 7:  <head id="Head1" runat="server">
Line 8:      <title></title>

之后,我尝试在生产服务器上将main.master.designer.vb文件中的该行从Protected WithEvents primtag As Global.System.Web.UI.HtmlControls.HtmlElement更改为Protected WithEvents primtag As Global.System.Web.UI.HtmlControls.HtmlGenericControl

Object reference not set to an instance of an object.

更新2

这可能与我的解决方案的汇编有关,我还查看了以下几篇文章:

代码语言:javascript
复制
http://briancaos.wordpress.com/2013/08/07/system-web-ui-htmlcontrols-htmliframe-is-not-compatible-with-the-type-of-control-system-web-ui-htmlcontrols-htmlgenericcontrol/
https://connect.microsoft.com/VisualStudio/feedback/details/736011/iframe-parser-error
http://forums.asp.net/t/1884696.aspx?help+required+with+iframes+on+aspx
http://support.microsoft.com/kb/941824
http://forums.asp.net/t/1686949.aspx

然后我检查本地机器上的IIS7.5设置,应用程序池被设置为ASP.NET 4.0,与我的生产服务器上的设置相同。我在Visual中的目标框架编译设置为.NET Framework4.5。

希望这提供了更多的洞察力,使其发挥作用。(请帮助:)

EN

回答 1

Stack Overflow用户

发布于 2013-11-30 20:42:13

可能的话,每个动态添加的属性都应该以任何特殊的前缀(例如"xml")开头。

检查this线程,这可能会有帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20060196

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档