473,508 Members | 4,751 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="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 3716
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
1285
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
4004
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
1503
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
1201
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
1473
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
2424
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
1437
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
2149
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
11732
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
7228
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,...
0
7128
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7332
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7058
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...
0
5635
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,...
0
4715
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...
0
3206
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...
0
1565
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 ...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.