+ -
当前位置:首页 → 问答吧 → 引发类型为“System.Windows.Forms.AxHost+InvalidActiveXStateException”的异常。

引发类型为“System.Windows.Forms.AxHost+InvalidActiveXStateException”的异常。

时间:2008-12-27

来源:互联网

我用asp写的一个网页,中间加入一个activeX控件,但出现了以上异常,在后台c#中的代码如下,请高手指教!
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows;
using AxGeoUrban3DWebLib;


public partial class _3D : System.Web.UI.Page
{
  public AxGeoUrban3DWebLib.AxGeoUrban3DWeb axGeoUrban3DWeb1;
  protected void Page_Load(object sender, EventArgs e)
  {
  axGeoUrban3DWeb1 = new AxGeoUrban3DWeb();
  axGeoUrban3DWeb1.LoadScene("D:\\3D\\三维数据模型\\浦口模型最新最小.gvp");
  }
  protected void Button1_Click(object sender, EventArgs e)
  {
  axGeoUrban3DWeb1.OnCtrlCommand(2);
  }
}

作者: ts_chen   发布时间: 2008-12-27

这是因为你页面上灭有加载该控件引起的,加下面代码,也许能解决!
this.axGeoUrban3DWeb1.BeginInit();
this.Controls.Add(this. axGeoUrban3DWeb1);
this. axGeoUrban3DWeb1.EndInit();

作者: zhbray   发布时间: 2009-06-03

我也遇到了类似的问题啊!

作者: haifeng_4216   发布时间: 2009-06-10

引发类型为“System.Windows.Forms.AxHost+InvalidActiveXStateException”的异常 解决
出现这类异常,多是引用第三方控件引起的。

在NEW时,需要初始化该对象。

  AxESACTIVEXLib.AxESActiveX ax = new AxESACTIVEXLib.AxESActiveX();

  ((System.ComponentModel.ISupportInitialize)(this.ax)).BeginInit();
  this.Controls.Add(ax);
  ((System.ComponentModel.ISupportInitialize)(this.ax)).EndInit();


这样就OK了。

作者: chenxiaocong1212   发布时间: 2010-03-10

web页面中,this.Controls.Add(ax)中ax须为Control类型,编译就通不过啊

作者: nj04w   发布时间: 2010-06-21

谢谢“chenxiaocong1212”

作者: ztntm   发布时间: 2011-09-05