Object in ASP page not firing events 
Author Message
 Object in ASP page not firing events

Hi - I have a request for ideas on this problem:

I've made an object that's supposed to be scriptable (to wrap SAX).
It works fine in a VB exe client and in client script on a DHTML page.
 It probably is also OK in a vbs too - I'll check that next. The
events reach those clients just fine.

The problem with using it on an ASP page is that the events it fires
are not coming to the page.  The object instantiates ok - I can even
access the properties from the ASP page.  And clearly the MSDN thought
this was possible.  And VI's script outline nicely shows the events
under the object - and double clicking the event causes VI to insert
the empty script for the handler, which I've fiddled with to no avail.
 Right now it looks about like this:

<OBJECT RUNAT=server PROGID=MyCompany.SaxContent id=saxcontent>
</OBJECT>
<SCRIPT ID=serverEventHandlersVBS LANGUAGE=VBScript RUNAT=Server>
Sub saxcontent_GotElement
    Response.Write(saxcontent.Element&"<BR>")
End Sub

And I've tried that trading the Response.write to just write "event
fired".  And I've tried the more long-hand way with the FOR= and
EVENT= in one script block that simply invokes a function in another
script block and with the FOR block doing the response.write and
several other combinations.

So I tried putting in an ADO connection on an asp page and could not
get that to fire an event either.  I *did* get an event fired from a
page object.  I suspect the difference could be that the page object
is firing from script, whereas my SAX wrapper object and the ADO
connection are traditional in-process COM objects.

Thus I checked the directory's isolation (I changed it from Low to
High ??) and tried a few other things to no avail. I have combed deja
(google) news here thoroughly and this is not a problem anyone has
written about that I can see.

If anyone has seen this before or knows something I could check or
try, please let me know.

TIA, C



Tue, 24 Feb 2004 13:49:29 GMT  
 Object in ASP page not firing events
How are you getting the server side ASP code to wait for events to occur (that's a loaded
question;-)...?

Server side ASP code is essentially linear -- when the logical end of the page is reached there is
an implicit Response.End.  There is no inherent "wait for events" capability in server side ASP.
Suppose there were and no events ever come due to a programming logic error?  The ASP code would
just hang until IIS eventually timed it out...

By contrast in a VB app, your form continues to run in an idle state until you explicitly close it,
giving it the opportunity to receive and handle events.

A possible solution is to use a combination of short Sleep calls (Win32 API) coupled with DoEvents
in your component that wraps SAX to expose your own version of Sleep.  Then it wouldn't matter if
the client code had any Sleep capabilities.

Another possible solution is to install MeadCo's ScriptX component on the server and use it's Wait
method (which is quite CPU friendly)...

Here's a simple VB class implementation (ActiveX DLL) that I have used from WSH hosted .vbs scripts
before WScript.Sleep existed (use it at your own risk in a server scenario)...  It was "quick and
dirty" code for only my own personal use.  If you choose to use it in a production setting, I
strongly suggest that you beef up the error handling.  I used a project reference to the win.tlb for
the Win32 API declarations for Sleep and GetTickCount.

=== MyClass.cls ===

Option Explicit

Dim bWaiting As Boolean

Public Sub Wait(ByRef vMilliseconds As Variant)

    If bWaiting Then Exit Sub

    Dim StopTime As Long

    'Let the client handle any errors...
    '
    On Error GoTo ErrHandler

    StopTime = Abs(CLng(vMilliseconds)) + GetTickCount

    bWaiting = True

    Do
        Sleep 50
        DoEvents
        If Not bWaiting Then Exit Sub
        'Debug.Print GetTickCount
    Loop While (GetTickCount < StopTime)

    Exit Sub

ErrHandler:
    Err.Raise Err.Number, "Wait", Err.Description

End Sub

Public Sub StopWait()

    bWaiting = False

End Sub

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup instead.
--

Quote:

> Hi - I have a request for ideas on this problem:

> I've made an object that's supposed to be scriptable (to wrap SAX).
> It works fine in a VB exe client and in client script on a DHTML page.
>  It probably is also OK in a vbs too - I'll check that next. The
> events reach those clients just fine.

> The problem with using it on an ASP page is that the events it fires
> are not coming to the page.  The object instantiates ok - I can even
> access the properties from the ASP page.  And clearly the MSDN thought
> this was possible.  And VI's script outline nicely shows the events
> under the object - and double clicking the event causes VI to insert
> the empty script for the handler, which I've fiddled with to no avail.
>  Right now it looks about like this:

> <OBJECT RUNAT=server PROGID=MyCompany.SaxContent id=saxcontent>
> </OBJECT>
> <SCRIPT ID=serverEventHandlersVBS LANGUAGE=vbscript RUNAT=Server>
> Sub saxcontent_GotElement
>     Response.Write(saxcontent.Element&"<BR>")
> End Sub

> And I've tried that trading the Response.write to just write "event
> fired".  And I've tried the more long-hand way with the FOR= and
> EVENT= in one script block that simply invokes a function in another
> script block and with the FOR block doing the response.write and
> several other combinations.

> So I tried putting in an ADO connection on an asp page and could not
> get that to fire an event either.  I *did* get an event fired from a
> page object.  I suspect the difference could be that the page object
> is firing from script, whereas my SAX wrapper object and the ADO
> connection are traditional in-process COM objects.

> Thus I checked the directory's isolation (I changed it from Low to
> High ??) and tried a few other things to no avail. I have combed deja
> (google) news here thoroughly and this is not a problem anyone has
> written about that I can see.

> If anyone has seen this before or knows something I could check or
> try, please let me know.

> TIA, C



Tue, 24 Feb 2004 23:48:45 GMT  
 Object in ASP page not firing events

Quote:
> How are you getting the server side ASP code to wait for events to occur (that's a loaded
> question;-)...?

Michael, hi! I was hoping you were still out there giving expert
advice - you've helped me before.

I wrote all that after giving up at 1 in the morning and woke up the
next day realizing the page was long gone (and its objects out of
scope and destroyed) before my first event could fire.  (But now I
wonder what's the point of the Server Objects and Events there in VI,
with little event symbols by the events the object can raise :-)  )

I will give the sleep feature you suggested a try.  Thanks so much!  C



Wed, 25 Feb 2004 05:50:49 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Intercepting User Defined Event fired from dll in ASP page

2. Determining which object fired event from event handler.

3. fire keyboard events form an onclick page event

4. Destroying ActiveX EXE Object Does Not Fire The Class_Terminate Event

5. click event not firing if lost_focus is firing first

6. ReadProperties event and WriteProperties event are not firing

7. ActiveX control event not working when in asp.net page

8. onreadystatechange event will not fire for a frame?

9. Events do not fire when node added to Doc by DOM

10. ActiveX custom event not firing HELP -- URGENT!

11. Custom event not firing HELP -- URGENT!

12. IE4.0pp2 - Radio buttons do not fire events?

 

 
Powered by phpBB® Forum Software