Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem loading .NET winform control dynamically in html page

13 views
Skip to first unread message

Peke

unread,
Oct 12, 2009, 5:25:01 AM10/12/09
to
Hi,

I have a problem loading an .NET winform control dynamically using
Javascript :

The winform control loads perfectly if I put it 'hardcoded'
...
<div id="myObject">
<object id=List1 height=400 width=555
classid=http:Controls/EmbedWinControl.dll#EmbedWinControl.PekeControl>
</object>
</div>
...

But when I want to load it via Javascript, it only shows the size (height,
width) of the object

...

<script type="text/javascript" language="JavaScript">
function Button1_onclick() {

objUserControl = document.createElement('object');
objUserControl.setAttribute('id', 'List2');
objUserControl.setAttribute('height', '400');
objUserControl.setAttribute('width', '555');
objUserControl.setAttribute('classid',
'http:Controls/EmbedWinControl.dll#EmbedWinControl.PekeControl');

myDiv = document.getElementById('myObject');
myDiv.appendChild(objUserControl);

}
</script>

...
<input id="Button1" type="button" value="button" onclick="return
Button1_onclick()" />
...
<div id="myObject"></div>
...


I 've also tried with the object InnerHTML, but that doesn't work either.

I'm using IE 8.

Any suggestions ?

Thx,

Peter

Allen Chen [MSFT]

unread,
Oct 12, 2009, 10:11:23 PM10/12/09
to
Hi Peter,

>I have a problem loading an .NET winform control dynamically using
>Javascript :

>The winform control loads perfectly if I put it 'hardcoded'
>...
> <div id="myObject">
> <object id=List1 height=400 width=555
>classid=http:Controls/EmbedWinControl.dll#EmbedWinControl.PekeControl>
> </object>
> </div>
>...

>But when I want to load it via Javascript, it only shows the size (height,
>width) of the object

Could you test the following project to see if it works?

http://cid-2fa13ebc6cc8e80f.skydrive.live.com/self.aspx/Public/WinFormContro
linASPNET.zip?ccr=7451

If it can work please compare the code with yours to troubleshoot.

Please let me know if you have any progress on this issue. I'll do my best
to follow up.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd...@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Allen Chen [MSFT]

unread,
Oct 12, 2009, 10:47:31 PM10/12/09
to
Hi Peter,

>But when I want to load it via Javascript, it only shows the size (height,
>width) of the object

Sorry I misread your question. Yes I've reproduced this issue. It looks
like there's no easy way to solve this problem. How about show/hide the
control instead of dynamically loading it? In the mean time I'll
investigate further to see if there's any possible way to dynamically load
WinForm control.

Peke

unread,
Oct 13, 2009, 2:21:01 AM10/13/09
to
Hi Allen,

Thanx for looking into this problem.
The hide/show trick is not an option.
I didn't mention it in the problem description, because I wanted to keep it
simple, but the PARAM's of the object tag will vary depending on what the
user is selecting in other fields, or even another control.

Kind regards,

Peter

Allen Chen [MSFT]

unread,
Oct 13, 2009, 9:30:06 PM10/13/09
to
Hi Peter,

>I didn't mention it in the problem description, because I wanted to keep
it
>simple, but the PARAM's of the object tag will vary depending on what the
>user is selecting in other fields, or even another control.

Thanks for your reply. So far I found no way to dynamically load the
control. If above is the main problem, please have a look at the project
mentioned in my first reply. It demonstrates how to use JavaScript to
assign value to the PARAM's value of the object. Please input some text in
the HTML textbox, click the HTML button. You'll see several message boxes
and finally the Text of the Label of the control is changed. Can it solve
this issue?

Allen Chen [MSFT]

unread,
Oct 15, 2009, 3:44:20 AM10/15/09
to
Hi Peter,

>I didn't mention it in the problem description, because I wanted to keep
it
>simple, but the PARAM's of the object tag will vary depending on what the
>user is selecting in other fields, or even another control.

I finally found a way to dynamically load winform control:

document.getElementById("forjsload").innerHTML = "<object
id='simpleControl1' height='300' width='300'><param name='S' value='Simple
Control'/></object>";
document.getElementById("simpleControl1").classid =
"http:WindowsControlLibrary3.dll#WindowsControlLibrary3.UserControl1";

Could you test it to see if it works?

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and

Peke

unread,
Oct 15, 2009, 11:43:59 AM10/15/09
to
Hello Allen,

For now, your suggested solution will be sufficient.
The example worked perfectly, but when I created my own winform control
(vb.net) I had problems with assigning the params dynamically via Javascript.
It took me a while to find out that the winform control assembly needed the
attribute ComVisible=True. Now it works just as it's supposed to do. I can
even call Public methods of the winform control in Javascript.

Thx for your help.

Peter

Peke

unread,
Oct 15, 2009, 11:51:47 AM10/15/09
to
Hello Allen,

Your suggestion works and will be sufficient for now.
I had some trouble with my own winform control (vb.net) to access the
properties via Javascript, but after I while I found out that I had to make
the winform control ComVisible(TRUE), which makes sense of course.
Now I can even access the public methods of the winform control via
Javascript.

Thx for your help.

Peter

0 new messages