So I've been searching for this everywhere. I can only find a couple of
links that say how to do this. And all of their ways have failed for
me.
I have the very basic scenario:
1) .NET 2.0 wizard generated UserControl. It does nothing except be a
big blue square in the browser. It has one public method: public
void SayHello() { MessageBox.Show("Hi"); }
namespace WCL2 {
public partial class UserControl1 : UserControl {
public UserControl1() {
InitializeComponent();
}
public void SayHello() {
MessageBox.Show("Hello there");
}
}
}
2) I have an html file that instantiates the object and displays a link
which if clicked calls the SayHello() method.
<html>
<body>
<center>
<object id="wcl2" height="100" width="400"
classid="http://localhost/WCL2.DLL#WCL2.UserControl1">
</object>
<br>
<a href="javascript:wcl2.SayHello();">Say Hello</a>
</center>
</body>
</html>
I don't think it can get any simpler than that. BUT IT DOESN'T WORK!
Ok, the control loads into the browser w/o issue. I've verfied this.
Click the link, I get the all to famous dialog saying "Object doesn't
support this property or method".
Now this link
http://blogs.msdn.com/andrewdownum/archive/2006/01/25/ControlInBrowserProperties
AndMethods.aspx
claims to have done it, albiet in a little different control. Is there
something wrong with UserControl versus Control with respect to IE
Hosting / Sourcing and javascript?
All help greatly appreciated
Gary F.
Jason Hales - 29 Mar 2006 14:03 GMT
There's a couple of things you can try.
Have you got the classid correct? Using gacutil /ldl can you confirm
that it is being download correctly.
Also I'd wrap the object tag in a form tag and then use an onclick
event to call a Javascript function:
<form id="Form1" method="post" runat="server">
<object id="wcl2" name="wcl2" height="100" width="400"
classid="http://localhost/WCL2.DLL#WCL2.UserControl1" VIEWASTEXT>
</object>
<a href="#" onclick="SayHello()">Say Hello</a>
<script>
SayHello()
{
document.Form1.wcl2.SayHello();
}
</script>
</form>