Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / March 2006

Tip: Looking for answers? Try searching our database.

How to call a IE hosted user control method via javascript?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gary F. - 28 Mar 2006 22:13 GMT
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>

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.