我有一個用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