473,725 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="javas cript">
window.alert("w indow 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="javas cript">
window.alert("w indow control event happen!");
</script>
....
<body>
<Object id="winObj1" classid="WinObj .dll#WinObj.Use rControl1"
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 3733
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:

[InterfaceTypeAt tribute(ComInte rfaceType.Inter faceIsIDispatch )]
public interface IMyEvents {
[DispId(1)]//Each event must have a unique DispId
void DoEvent();
}

then your winform control must implement it:

[ComSourceInterf aces(typeof(IMy Events))]
public class MyControl : Control
{
public event DoEventHandler DoEvent;

.....
-- bruce (sqlwork.com)

jy**********@gm ail.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="javas cript">
window.alert("w indow 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="javas cript">
window.alert("w indow control event happen!");
</script>
...
<body>
<Object id="winObj1" classid="WinObj .dll#WinObj.Use rControl1"
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.Use rControl1"
VIEWASTEXT>
<param name="ClientID" value="<%= Label1.ClientID %>" />
</Object>

<script language="javas cript">
function doJS()
{
var o = document.GetEle mentByID("winOb j1");
alert(o.ClientI D);
}

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:

[InterfaceTypeAt tribute(ComInte rfaceType.Inter faceIsIDispatch )]
public interface IMyEvents {
[DispId(1)]//Each event must have a unique DispId
void DoEvent();

}

then your winform control must implement it:

[ComSourceInterf aces(typeof(IMy Events))]
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
1301
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
4025
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 same way a menu does. To do this my control needs to get notified when the user tried to click off of it. The Leave and LostFocus events of the UserControl work most of the time but not always. For example, if they click on a part of the form...
1
1512
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 caugth it, when it fired from th main thread or from the code in external event handler such as Butto clicked event. But when fired from the worker thread, th "System.Reflection.TargetExceltion : Object does not match target type
0
1217
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 about this: i have written an WinForm-UserControl, containing a Toolbar. Everything works fine, every clickevent fires and on some actions i popup modal Dialogs. No problems here.
1
1482
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 addition work may have been done. This web page usercontol interaction was easy in VB6. Using VB.Net I have been able to create the usercontrol for the web page and have also been able to pass parameters in via the <object> tag. I have not...
0
2438
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 (http://support.microsoft.com/kb/810852), but then I realized that the hotfix mentioned was in .Net v1.1, which I am using. I took the sample from that article and recreated the situation I see in my application. (Code included below.) If you run the...
0
1460
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 winform holding that control. First I want toaccess the Click functionality of each toolbar button(usercontrol) in my winform which holding the usercontrol; secondlywants to override the methods of usercontrol in winformaccordingly to the click event of...
3
2158
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 way, I could modify the properties of the panel within the UserControl when I place a UserControl on a Form. Or so I thought. I can set the properties of the Panel within the UserControl via the Properties Window, but none of the changes made to...
11
11761
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 in the validated event. Is there a way to know if all validated controls pass validation when the user clicks an OK button? In ASP.Net there's the Page.IsValid method. Is there something similar in winforms, or do I still have to write an...
0
8889
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9179
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8099
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3228
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.