通过code-落后导致错误类型(System.Web.UI.HtmlControls.HtmlElement)添加属性HTML标记不兼容 [英] Adding attribute to html tag via code-behind results in error type (System.Web.UI.HtmlControls.HtmlElement) is not compatible

查看:605
本文介绍了通过code-落后导致错误类型(System.Web.UI.HtmlControls.HtmlElement)添加属性HTML标记不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试属性在我的母版添加到我的HTML标签:

 <!DOCTYPE HTML PUBLIC -  // W3C // DTD XHTML 1.0过渡// ENhttp://www.w3.org/TR/xhtml1/DTD/ XHTML1-transitional.dtd>
< HTML的xmlns =htt​​p://www.w3.org/1999/xhtmlID =primtag=服务器>

像这样在code背后:

  prmimaryhtml_tag.Attributes.Add(郎,恩)

我得到这个错误:

 分析器错误说明:该请求提供服务所需资源的分析过程中出现错误。请检查下列特定分析错误详细信息并适当地修改源文件。分析器错误信息:基类包括字段primtag,但其类型(System.Web.UI.HtmlControls.HtmlElement)不与(System.Web.UI.HtmlControls.HtmlGenericControl)控制的类型兼容。源错误:
4号线:
5号线:< D​​OCTYPE HTML PUBLIC - // W3C // DTD XHTML 1.0过渡// ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
6号线:其中; HTML的xmlns =htt​​p://www.w3.org/1999/xhtmlID =primtag=服务器>
7号线:其中,头ID =头像1=服务器>
8号线:其中,标题>< /标题>源文件:/main.master行:6

我还检查 main.master.designer.vb 并持有该行:

 保护WithEvents就primtag作为Global.System.Web.UI.HtmlControls.HtmlElement

现在,最奇怪的事情是:这个code正确的工作我的本地计算机上,但不是我生产服务器上。我不知道发生了什么或者造成这种不同的行为。

我也看了这个帖子:设置页面主HTML在C#中标签

更新
当我的情况如下:

main.master.designer.vb

 保护WithEvents就primtag作为Global.System.Web.UI.HtmlControls.HtmlElement

main.master.aspx

 < HTML的xmlns =htt​​p://www.w3.org/1999/xhtmlID =primtag=服务器>

main.master.aspx.vb

注释这一行:

 'primtag.Attributes.Add

我得到:

 分析器错误说明:该请求提供服务所需资源的分析过程中出现错误。请检查下列特定分析错误详细信息并适当地修改源文件。分析器错误信息:基类包括字段primtag,但其类型(System.Web.UI.HtmlControls.HtmlElement)不与(System.Web.UI.HtmlControls.HtmlGenericControl)控制的类型兼容。源错误:
4号线:
5号线:< D​​OCTYPE HTML PUBLIC - // W3C // DTD XHTML 1.0过渡// ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
6号线:其中; HTML的xmlns =htt​​p://www.w3.org/1999/xhtmlID =primtag=服务器>
7号线:其中,头ID =头像1=服务器>
8号线:其中,标题>< /标题>

之后,我试图改变在main.master.designer.vb文件专线 primtag作为Global.System.Web.UI.HtmlControls.HtmlElement保护WithEvents就保护primtag作为Global.System.Web.UI.HtmlControls.HtmlGenericControl 在生产服务器上WithEvents就我得到的:

对象引用未设置到对象的实例。

更新2

这可能是与我的解决方案的编制,我还检查了这些职位:

<$p$p><$c$c>http://briancaos.word$p$pss.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.NET4.0,同我的生产服务器上。
我在Visual Studio目标框架编制设定到.NET Framework 4.5。

希望这提供了在得到这个工作更多的见解。请帮助:)


解决方案

也许,每一个动态添加的属性应与任何特殊(例如,XML)preFIX。

启动

线程,这可能会有帮助。

When I try to add an attribute to my html tag in my masterpage:

<!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">

like so in code behind:

prmimaryhtml_tag.Attributes.Add("lang", "en")

I get this error:

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 

I also checked main.master.designer.vb and it holds this line:

Protected WithEvents primtag As Global.System.Web.UI.HtmlControls.HtmlElement

Now, the weirdest thing is: this code works correct on my local machine, but not on my production server. I don't know what's causing this different behavior either.

I also looked at this post: set pages main html tag in c#

UPDATE When my situation is as follows:

main.master.designer.vb

 Protected WithEvents primtag As Global.System.Web.UI.HtmlControls.HtmlElement

main.master.aspx

<html xmlns="http://www.w3.org/1999/xhtml" ID="primtag" runat="server">

main.master.aspx.vb

commented this line:

'primtag.Attributes.Add

I get:

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>

After that I tried changing that line in the main.master.designer.vb file from Protected WithEvents primtag As Global.System.Web.UI.HtmlControls.HtmlElement to Protected WithEvents primtag As Global.System.Web.UI.HtmlControls.HtmlGenericControl On the production server I get:

Object reference not set to an instance of an object.

UPDATE 2

It may have something to do with compilation of my solution, I also checked these posts:

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

I then check my IIS7.5 setting on local machine, there the application pool was set to ASP.NET4.0, same as on my production server. My target framework compilation in Visual Studio is set to .NET Framework 4.5.

Hopefully this provides more insights in getting this to work. Please help :)

解决方案

Possibly, each dynamically added attribute should start with any special (for example, the "xml") prefix.

Check this thread, which may be helpful.

这篇关于通过code-落后导致错误类型(System.Web.UI.HtmlControls.HtmlElement)添加属性HTML标记不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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