473,326 Members | 2,680 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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

Hi,

In my current project, I need to embed an .NET winform usercontrol in
the aspx page (via <Objecttag). 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();
}

Mar 22 '07 #1
2 3708
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)

jy**********@gmail.com wrote:
Hi,

In my current project, I need to embed an .NET winform usercontrol in
the aspx page (via <Objecttag). 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();
}
Mar 22 '07 #2
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 <nos...@nospam.comwrote:
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)
Mar 22 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Nicole - ASP/C# Beginner | last post by:
I am trying to kick off an custom event in a usercontrol that the webpage will listen and preform some actions if the event is fired from within my usercontrol
1
by: Rhy Mednick | last post by:
I'm creating a custom control (inherited from UserControl) that is displayed by other controls on the form. I would like for the control to disappear when the user clicks outside my control the...
1
by: panitw | last post by:
I have a UserControl hosted in Internet Explorer. I create a worke thread to do some task and want to fire an event when the worker threa finish working. The event works fine, javascript can...
0
by: Hilmar Demant | last post by:
Hi, i've experienced something weird, and its probably not an special ASP.NET-issue, but containing several techniques i think its adequate to post it here. Hopefully someone knows anything...
1
by: DonR | last post by:
History: In VB6 I could create an OCX that had the ability to accept paramenters from a web page <object> tag, do some work, then fire an event back to VBScript or JavaScript on the web page where...
0
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852...
0
by: Syed Zaidi via .NET 247 | last post by:
I am working on a small project in which i want to develop acustom toolbar skeleton for handling database navigation. I havecreated a usercontrol consist of a toolbar inherits fromusercontrol and...
3
by: Don | last post by:
I've created a custom UserControlwithin which I have placed a Panel. I've changed the Panel's "Modifier" property to Public so that it appears in the Properties Window of the UserControl. This...
11
by: jjbutera | last post by:
I know how to use the ErrorProvider in my winforms..or do I? I validate the values and set the ErrorProvider in the validating event. If not valid, I set e.Cancel = True. I clear the ErrorProvider...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.