我有一个用c#编写的非常简单的用户控件,并且编译成一个dll。我使用对象标签将该控件放入一个aspx页面,然后尝试在javascript中对其进行操作。我有其他控件可以正常工作,但由于某种原因,这不是。下面的代码:ASPX页面中的用户控件不能与javascript一起工作
using System.Windows.Forms;
namespace FileBrowser {
public partial class theBrowser : UserControl {
public theBrowser() {
InitializeComponent();
MessageBox.Show("TBI");
}
public string theFile = "foobar";
}
}
这里的网页代码:
<object id='fileBrowserControl' classid='http:FileBrowser.dll#FileBrowser.theBrowser'>
<span>File control did not initialize.</span>
然后
<script type="text/javascript">
$(function() {
var mfc = $('#fileBrowserControl')[0];
alert(mfc.theFile);
});
当网页加载完毕后,在MessageBox显示,构造函数已经解雇了,但是javascript警报给了组件字符串'未定义'。这是一个精简版,在真实版本中,我也无法从javascript调用公共函数。我得到错误,“对象不支持这个属性或方法。”
我明显错过了一件非常简单的事情,但我没有看到它。谢谢你的帮助。 Jon
你打算使用Web用户控件,而不是一个形式的用户控件? – 2012-03-26 21:14:12
似乎并不重要。我认为问题的一部分是我制作的控件作为ActiveX控件工作,并且我无法在VS2008中找到它。 – Jon 2012-03-26 21:32:29
你正在使用ASP.NET或WinForms? – jrummell 2012-03-27 15:08:49