Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > how to let an embedded .NET winform usercontrol fire an event (via javascript) in webpage

Reply
Thread Tools

how to let an embedded .NET winform usercontrol fire an event (via javascript) in webpage

 
 
jyanmin.fang@gmail.com
Guest
Posts: n/a
 
      03-22-2007
Hi,

In my current project, I need to embed an .NET winform usercontrol in
the aspx page (via <Object> tag). This winform usercontrol has an
event called DoEvent (void DoEvent()). This winform usercontrol will
fire this event upon certain action by the user. I tried to let the
aspx page subscribe to this event via

<script for="winObj1" event="DoEvent()" language="javascript">
window.alert("window control event happen!");
</script>

but the event was never fired. Any idea?

here are some code snippet, for aspx page
<script for="winObj1" event="DoEvent()" language="javascript">
window.alert("window control event happen!");
</script>
....
<body>
<Object id="winObj1" classid="WinObj.dll#WinObj.UserControl1"
VIEWASTEXT>
</Object
<body>

for winform usercontrol

delegate void DoEventHandler();
public event DoEventHandler DoEvent;

public void onDoEvent()
{
if(DoEvent != null)
DoEvent();
}

 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      03-22-2007
your winform has to implement an idispatch interface and be set to full
trust (user sets website to full trust or uses caspol.exe) to raise
events in the browser:

define idispatch click event:

[InterfaceTypeAttribute(ComInterfaceType.InterfaceI sIDispatch)]
public interface IMyEvents {
[DispId(1)]//Each event must have a unique DispId
void DoEvent();
}

then your winform control must implement it:

[ComSourceInterfaces(typeof(IMyEvents))]
public class MyControl : Control
{
public event DoEventHandler DoEvent;

.....


-- bruce (sqlwork.com)

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi,
>
> In my current project, I need to embed an .NET winform usercontrol in
> the aspx page (via <Object> tag). This winform usercontrol has an
> event called DoEvent (void DoEvent()). This winform usercontrol will
> fire this event upon certain action by the user. I tried to let the
> aspx page subscribe to this event via
>
> <script for="winObj1" event="DoEvent()" language="javascript">
> window.alert("window control event happen!");
> </script>
>
> but the event was never fired. Any idea?
>
> here are some code snippet, for aspx page
> <script for="winObj1" event="DoEvent()" language="javascript">
> window.alert("window control event happen!");
> </script>
> ...
> <body>
> <Object id="winObj1" classid="WinObj.dll#WinObj.UserControl1"
> VIEWASTEXT>
> </Object
> <body>
>
> for winform usercontrol
>
> delegate void DoEventHandler();
> public event DoEventHandler DoEvent;
>
> public void onDoEvent()
> {
> if(DoEvent != null)
> DoEvent();
> }
>

 
Reply With Quote
 
 
 
 
jyanmin.fang@gmail.com
Guest
Posts: n/a
 
      03-22-2007
Thanks, Bruce. This works nicely. The event is fired now.

One more question, if I don't set the Attribute to the class, then in
the javascript I can access the winform's Property. here is the code
(ClientID is the public property defined in th winform control)

<Object id="winObj1" classid="WinObj.dll#WinObj.UserControl1"
VIEWASTEXT>
<param name="ClientID" value="<%= Label1.ClientID%>" />
</Object>

<script language="javascript">
function doJS()
{
var o = document.GetElementByID("winObj1");
alert(o.ClientID);
}

But if I set the Attribute to the winform class, then o.ClientID is
undefined. I assume this problem can be fixed by setting some
Attribute to the property.

Thanks

Jimmy

On Mar 22, 12:25 pm, bruce barker <(E-Mail Removed)> wrote:
> your winform has to implement an idispatch interface and be set to full
> trust (user sets website to full trust or uses caspol.exe) to raise
> events in the browser:
>
> define idispatch click event:
>
> [InterfaceTypeAttribute(ComInterfaceType.InterfaceI sIDispatch)]
> public interface IMyEvents {
> [DispId(1)]//Each event must have a unique DispId
> void DoEvent();
>
> }
>
> then your winform control must implement it:
>
> [ComSourceInterfaces(typeof(IMyEvents))]
> public class MyControl : Control
> {
> public event DoEventHandler DoEvent;
>
> ....
>
> -- bruce (sqlwork.com)


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Embedded Winform - trapping event in host javascript Fresno Bob ASP .Net 0 08-24-2009 12:44 PM
WebPermission security issue with WinForm control in a webpage kb ASP .Net 0 08-30-2007 09:58 PM
Security Exception - Winform usercontrol hosted in ASP.NET Scott Leonard ASP .Net Security 2 12-22-2004 06:23 PM
Question about embedded winform controls A Lonely Programmer ASP .Net 5 02-17-2004 03:15 PM



Advertisments