I’ve got a very simple user control written in c# and compiled into a dll. I place that control into an aspx page using an object tag and then try and do things with it in javascript. I’ve got other controls that work just fine, but for some reason this one doesn’t. Here’s the code:
using System.Windows.Forms;
namespace FileBrowser {
public partial class theBrowser : UserControl {
public theBrowser() {
InitializeComponent();
MessageBox.Show("TBI");
}
public string theFile = "foobar";
}
}
Here’s the web page code:
<object id='fileBrowserControl' classid='http:FileBrowser.dll#FileBrowser.theBrowser'>
<span>File control did not initialize.</span>
Then
<script type="text/javascript">
$(function() {
var mfc = $('#fileBrowserControl')[0];
alert(mfc.theFile);
});
When I load the page, the MessageBox shows that the constructor has fired, but the javascript alert gives ‘undefined’ for the component string. This is a stripped down version, in the real version, I also cannot call public functions from javascript. I get the error, ‘the object doesn’t support this property or method.’
I’m obviously missing something really simple, but I don’t see it. Thanks for any help.
Jon
Solved! Thanks for the input.
Here’s an article that shows how:
http://www.olavaukan.com/2010/08/creating-an-activex-control-in-net-using-c/