-
December 15th, 2008, 06:12 PM
#1
[RESOLVED] Can't Pass Data From IE to a User Control
I have a controll that i have built for testing. It will open up in IE and will run the simple code it has inside it. However i am not able to pass it any data. Im using VS 2008 C# and IE 7.
Clicking on the button in the form dose not cause any action in the controll
This is my control
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace WindowsControlLibrary1
{
public partial class UserControl1 : UserControl
{
private string someString = "";
private bool isSet;
public UserControl1()
{
InitializeComponent();
}
public string SomeString
{
set { someString = value; }
}
private void timer1_Tick(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToLongDateString();
button1.Text = someString;
textBox1.Text = (isSet == true)?"Fish":"Food";
isSet = !isSet;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
Here is the web page
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body color=white>
<hr>
<font face=arial size=1>
<OBJECT id="myControl1" name="myControl1" classid="WindowsControlLibrary1.dll#WindowsControlLibrary1.UserControl1" width=150 height=150>
</OBJECT>
</font>
<form name="frm" id="frm">
<input type="text" name="txt" value="enter text here"><input type=button value="Click me" onClick="doScript();">
</form>
<hr>
</body>
<script language="javascript">
function doScript()
{
myControl1.SomeString = frm.txt.value;
}
</script>
</html>
Any ideas?
-
December 15th, 2008, 08:31 PM
#2
Re: Can't Pass Data From IE to a User Control
I don't think Javascript can interact effectively with an outside object (user control), like yours.
You would have to have a button1.Click event handler in the DLL.
Oh, and this is intriguing to me, so how did you have IE7 recognize a control like that? Is there anything you had to do, like put it in a special folder, or use it as an addon?
-
December 16th, 2008, 09:43 AM
#3
Re: Can't Pass Data From IE to a User Control
Explorer supports using windows controls as objects in the browser. The control is just a dll and the hooks for access to the browser are public properties. I have seen multiple examples where the control is able to receive data. However I have not been able to reproduce those results.
It's frustrating because IE uses its own DOM concepts in Jscript, MS's implementation of JavaScript, and before i was tying to get a Java applet to work consistently but apparently they have their own caveats with applets as well. IE is such a crap platform to develop for.
-
December 17th, 2008, 07:05 AM
#4
Re: Can't Pass Data From IE to a User Control
I had this problem recently - you have to make the control COM visible to access its methods.
e.g.
Code:
using System.Runtime.InteropServices;
[ComVisible(true)]
public partial class UserControl1 : UserControl
Darwen.
-
December 17th, 2008, 10:36 AM
#5
Re: Can't Pass Data From IE to a User Control
I added the statement with no additional results. Could you please proved a complete example. Just a control with a text box that gets updated from JavaScript in the page.
Also i added this script to the page to see if it would uncover the SomeText interface but I don't know if the property would be visible.
Code:
for (var i in myControl1)
{
document.write(i);
document.write("<br/>");
}
-
December 17th, 2008, 11:59 AM
#6
Re: Can't Pass Data From IE to a User Control
I was able to find someone's code on line that i was able to use on my system and the issue was based in COM visibility. The way i solved it was by adding the add COM visibility in the project properties.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|