[心缘地方]同学录
首页 | 功能说明 | 站长通知 | 最近更新 | 编码查看转换 | 代码下载 | 常见问题及讨论 | 《深入解析ASP核心技术》 | 王小鸭自动发工资条VBA版
登录系统:用户名: 密码: 如果要讨论问题,请先注册。

[备忘]asp.net中,(System.Web.UI.HtmlControls.HtmlIframe) is not compatible with the type of control (Sys

上一篇:[备忘].net下安装Spread控件的费劲经历~~
下一篇:[备忘]关于request流只能读取一次的问题。

添加日期:2014/11/11 22:05:44 快速返回   返回列表 阅读9554次
aspx中用了一个<iframe runat="server".../>
结果报错:
(System.Web.UI.HtmlControls.HtmlIframe) is not compatible with the type of control (System.Web.UI.HtmlControls.HtmlGenericControl)

变量声明已经是HtmlIframe了,但奇怪为什么当做HtmlGenericControl了。

百思不得其解~~

百度半天不行,最后翻墙上google~~

-----------------------------------------------------
http://stackoverflow.com/questions/17809446/iframe-parser-error-after-upgrading-to-net-4-5

简单的说,就是framework 4.5版本开始,<iframe>变成了HtmlIframe类,
4.5版本之前,是HtmlGenericControl类。

web.config里有个targetFramework属性,要是4.5,就把iframe编译成HtmlIframe,
要是4.0,就给编译成HtmlGenericControl。

我靠,一看web.config,里面妥妥的写着
<compilation debug="true" targetFramework="4.0" />
<httpRuntime targetFramework="4.0" />

我去~~~改成4.5,瞬间好~~

另外:
你安装了framework 4.5,但IIS里怎么看都是4.0,奇怪吧?

看C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5
下的dll,版本其实都是4.0,

所以,人家把4.5当做是4.0的升级包而已,所以显示着4.0~~
-----------------------------------------------------
复制一段过来:
The basic problem is an incompatibility between the object generated from your Web Forms IFRAME server control by the ASP.NET compiler (which compiles ASPX and ASCX files to C# or VB code) and the type of the variable corresponding to that control in your Web Forms code behind. 

An IFRAME server control (<iframe id="frame" runat="server" />) will be parsed as an control of a particular type. 

In ASP.NET 4 an IFRAME server control will be an HtmlGenericControl control.

In ASP.NET 4.5 an IFRAME server control will be an HtmlIframe control.

The problem can be fixed by making sure that the targetFramework attribute on the compilation element in your web.config file agrees with the Target Framework property of your project and that the variable corresponding to your IFRAME server control matches the type of control the ASP.NET compiler will generate.

An ASP.NET 4 project that has been converted to .NET Framework 4.5 in Visual Studio 2013 will modify the project's web.config file so that targetFramework attribute of the compilation element has a value of "4.5" (<compilation targetFramework="4.5"/>). This causes the ASP.NET compiler to treat the IFRAME server control as a HtmlIframe control. This can cause a problem if the Web Forms code behind control variable is still an HtmlGenericControl. The error you see is like this:

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

The solution to the previous error is to update the type of the server control variable that corresponds to the IFRAME server control. You can do this by re-saving the Web Forms HTML file which will cause the designer file to be regenerated. As far as I can see (in Visual Studio 2013 at least) changing the control ID is not necessary. If the server control variable is in the code behind file, it must be updated manually.

An ASP.NET 4.5 project where the code behind variable is an HtmlIframe will experience a similar but different issue if the targetFramework attribute of the compilation element in the web.config file has a value of "4.0" (<compilation targetFramework="4.0"/>). This causes the ASP.NET compiler to treat the IFRAME server control as a HtmlGenericControl control. The error you see is like this:

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

The way to fix the previous error is to make sure the web.config compilation settings agree with your project's Target Framework attribute. In this case the targetFramework attribute of the compilation element in the web.config should have a value of "4.5".

<compilation targetFramework="4.5"/>

Note: Setting the httpRuntime element's targetFramework attribute to 4.5 will also have the effect of setting the compilation element's targetFramework attribute to 4.5. See http://blogs.msdn.com/b/webdev/archive/2012/11/19/all-about-httpruntime-targetframework.aspx for more info.

Note 2: There is no <asp:HtmlIframe> tag. Registering the tag prefix "asp" to the System.Web.UI.HtmlControls namespace is not something that is required to use an IFRAME server control.
 

评论 COMMENTS
没有评论 No Comments.

添加评论 Add new comment.
昵称 Name:
评论内容 Comment:
验证码(不区分大小写)
Validation Code:
(not case sensitive)
看不清?点这里换一张!(Change it here!)
 
评论由管理员查看后才能显示。the comment will be showed after it is checked by admin.
CopyRight © 心缘地方 2005-2999. All Rights Reserved