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

Discussion in 'ASP .Net' started by jyanmin.fang@gmail.com, Mar 22, 2007.

  1. Guest

    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();
    }
     
    , Mar 22, 2007
    #1
    1. Advertising

  2. bruce barker Guest

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

    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.InterfaceIsIDispatch)]
    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)

    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();
    > }
    >
     
    bruce barker, Mar 22, 2007
    #2
    1. Advertising

  3. Guest

    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 <> 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.InterfaceIsIDispatch)]
    > 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, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luigi Donatello Asero

    Let or not let the text float

    Luigi Donatello Asero, Jan 15, 2004, in forum: HTML
    Replies:
    6
    Views:
    484
    Steve R.
    Jan 15, 2004
  2. kb
    Replies:
    0
    Views:
    492
  3. Fresno Bob
    Replies:
    0
    Views:
    461
    Fresno Bob
    Aug 24, 2009
  4. Scott Leonard

    Security Exception - Winform usercontrol hosted in ASP.NET

    Scott Leonard, Dec 3, 2004, in forum: ASP .Net Security
    Replies:
    2
    Views:
    282
    Scott Leonard
    Dec 22, 2004
  5. prabhu_27_84
    Replies:
    0
    Views:
    115
    prabhu_27_84
    Jul 11, 2007
Loading...

Share This Page