How to invoke .NET 2.0 user control method via javascript hosted in IE 6?

I've looked hi and low for this and I cannot seem to find an answer to my problem.

So, I have a very simple C# .NET 2.0 user control (gen'd by the wizard) that does nothing but be a blue square. I added 1 method, 1 property. This is very similar to other examples out there.

namespace WCL2 {
public partial class UserControl1 : UserControl {
public UserControl1() {
InitializeComponent();
}
public virtual void SayHello() {
MessageBox.Show("Hello there");
}
public string MyColor {
get { return ColorTranslator.ToHtml(this.BackColor); }
set { this.BackColor = ColorTranslator.FromHtml(value); }
}
}
}

I also have the an html file with javascript which calls the method and property. The color property is called two ways, via param and via invocation. The param way works. The invocation does not. Trying to invoke my one method gives me the "Object doesn't support method or property" dialog.

<html>
<body>
<center>
<object id="wcl2" height="100" width="400" classid="http://localhost/WCL2.DLL#WCL2.UserControl1" VIEWASTEXT>
<param name="MyColor" value="Blue"/>
</object>
<br>
<a href=wcl2.SayHello();">Say Hello</a>
<br>
<input type="text" id="colorName" value="Green"/>
<input type="button" onclick="wcl2.MyColor = colorName.value"/>
</center>
</body>
</html>

What does work:
1) The control renders as expected in the browser
2) User control is listed in the GAC as expected

What hasn't worked:
1) Bumping up perm set to FullTrust
2) Strong name and more FullTrust
3) Various rewrites of the javascript

Any ideas what I might be doing wrong My dumb little test is almost like others that I've seen in blogs and articles. I'm overlooking something, I just don't know what.

Lastly, I'm *ASSUMING* that it is not necessary to COM-ify my UserControl given that 1) IE has special code in it to make it .NET-control-aware, 2) the doc for UserControl class says that derivations can be hosted in IE.

Thanks

Gary F.



Answer this question

How to invoke .NET 2.0 user control method via javascript hosted in IE 6?

  • Raven Jake

    Yep, tried that. I gave FullTrust permissions to both LocalIntranet and Internet. It didn't work. I tried strong naming the control, creating a new code group, associating the control to the group using the strong name, and giving the code group FullTrust. That didn't work. I also tried various security configs in the IE browser options. None of that worked.

    I'm at a loss.

    Gary F.


  • Clay Culver

    Hi Gary,

    Did you try setting up Code Access Security for your LocalIntranet_Zone and Internet_Zone By default all .NET assemblies can execute on local computer, which is MyComputer zone. Many operations fail on other zones if CAS is not set.

    Regards,

    Raghu



  • aaborkar

    Oh geez, so, ok, I found my answer. The answer is that the project has to be "Registered for COM interop" *and* that the COM visible attribute in AssemblyInfo.cs has to be true - [assembly: ComVisible(true)]

    The only time I ever saw mention of these two actions is when doing .NET -> Javascript communication, like in the case of the .NET control firing events for Javascript to sink.


  • How to invoke .NET 2.0 user control method via javascript hosted in IE 6?