Help: Win Controls Hosted in IE - Cannot pass/retrieve parameters in JS

T

tomromanul

Hi all,

I built a Windows Froms user control and I use it in IE 6+. It
functions properly (it displays properly in IE and executes code, such
as displaying a message box), except that in the web page I cannot do
any scripting (javascript) against it. This control has a public
property Text2, which is initialized properly:
<object id="simpleControl1"
classid="http:WinControlCS.dll#WinControlCS.WinControl"
height="300" width="300" VIEWASTEXT>
<param name="Text2" value="123" />
</object>

However, when I try to get/set this property in JS, it won't work, I
get 'undefined':
<script>
function ChangeText() {
text1.value=simpleControl1.Text2;
}

</script>

If I don't specify the property Text2, I get '[object]':
<script>
function ChangeText() {
text1.value=simpleControl1;
}

</script>

This suggests me that the object simpleControl1 exists, but I just
don't know how to access the Text2 property in JS.

I set full trust for the Local Intranet, no luck.

FYI, there is a sample online at gotdotnet and if I point the browser
to it, it works:
http://samples.gotdotnet.com/quickstart/winforms/Samples/IeSourcing/V...
This example passes a value to the Text property of the control,
similarly with I'm trying to do.

I tried with and without this line with no luck: <param name="Text2"
value="123" />

I tried a builtin property, BackColor, with exactly the same result: It
can be initialized, but it cannot be changed in JS.

I tried with controls written in both C# and VB. Here is the C#
version:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WinControlCS
{
public partial class WinControl : UserControl
{
public WinControl()
{
InitializeComponent();
}

private void WinControl_Load(object sender, EventArgs e)
{

}

public string Text2
{
get { return richTextBox1.Text; }
set { richTextBox1.Text = value; }
}

private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(richTextBox1.Text);
}

private void openToolStripMenuItem_Click(object sender,
EventArgs e)
{
MessageBox.Show("Click File/Open");
}
}

}

I use VS 2005 on XP sp2.

Please help. I am stuck as I don't find any information on newsgroups.
Thanks
Tom
 
T

tomromanul

Is anyone from Microsoft who can help me with this? Do you need more
details? In the end, is it possible to get/set properties of a Windows
Forms control hosted in IE using JavaScript? If yes, what do I do
wrong?
Thanks a bunch,
Tom
 
G

Guest

You need to create a public interface and register the assembly for COM
interop in order to assign properties via Javascript

i.e.

// you are going to want to check my Syntax im a VB guy
public interface IWinControlCS{
public string Text2;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top