asp.net – 通过代码隐藏结果??在错误类型(System.Web.UI.HtmlCo
当我尝试在我的母版页中向我的html标记添加属性时:
<!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"> 像代码背后一样: prmimaryhtml_tag.Attributes.Add("lang","en") 我收到此错误: 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并保留了这一行: Protected WithEvents primtag As Global.System.Web.UI.HtmlControls.HtmlElement 现在,最奇怪的是:这个代码在我的本地机器上正常工作,但在生产服务器上却没有.我不知道是什么导致了这种不同的行为. 我也看过这篇文章:set pages main html tag in c# UPDATE 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 评论这一行: 'primtag.Attributes.Add 我明白了: 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更改为Global.System.Web.UI.HtmlControls.HtmlElement to Protected WithEvents primtag As Global.System.Web.UI.HtmlControls.HtmlGenericControl On我得到的生产服务器: 你调用的对象是空的. 更新2 它可能与我的解决方案的编译有关,我还检查了这些帖子: 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.NET4.0,与我的生产服务器上的相同. 希望这为实现这一目标提供了更多见解.请帮忙 :) 解决方法
可能每个动态添加的属性应该以任何特殊(例如,“xml”)前缀开头.
检查this线程,这可能会有所帮助. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |