views:

91

answers:

2

hey all ,

background -

I'm using an activx that allow me to access some information on the client side,

By using the activex events and callback i'm updating server side from client.

i wrote a user control that register all activex's events so when one of the events occuer there is a callback to the server that handle this event.

I need to write some other user controls based on this control so on every callback this user controls will be render on the client side.

My question is -

what is the best way to make a shared infrastructure that handle this events and render the right content base on user controls? is there any other ways i can use ?

thanks!

A: 

A little more info on your project would be helpful, but I think you would be well served using two approaches, one to handle the logic/events... and one to actually handle the visual updates - with some glue in the middle to make it all work like a charm.

First, the events. I could envision some sort of javascript class that registers with your activex control and binds methods to the various event handlers. This class would also expose methods you could bind functions to that would provide callbacks to your display logic.

Second, I would recommend using a library like jQuery to help with the heavy lifting of modifying the user page.

function eventTrap() {}
eventTrap.prototype.hookActiveX() { // your code to attach to your activex object }
eventTrap.prototype.register(event, callback) { // code to register for an event and callback }

// actually use it...
var trapObj = new eventTrap();
trapObj.hookActiveX();
trapObj.register("click", function(){alert('click');});
Goyuix
A: 

hey! thanks for your fast reply,

first of all , i'm calling the activex using object tags,

    HtmlGenericControl SkypeObject = new HtmlGenericControl("object");
    SkypeObject.Attributes.Add("id", "Skype");
    SkypeObject.Attributes.Add("codeBase", "http://ip/Skype4COM.dll");
    SkypeObject.Attributes.Add("classid", "clsid:830690FC-BF2F-47A6-AC2D-330BCB402664");
    SkypeObject.Attributes.Add("name", "Skype");

write callback :

    string SkypeAsyncCallbackOnEvent = ClientScript.GetCallbackEventReference(this, "values", ClientScriptName, "context", true);

    string SkypeCallbackFunction = "\n<script>\n";
    SkypeCallbackFunction += "function SkypeCallback(values,context) {\n";
    SkypeCallbackFunction += SkypeAsyncCallbackOnEvent + "\n}\n";
    SkypeCallbackFunction += "</script>";

then i register the active'x events :

        string SkypeOnUserStatusChange = "\n<script for=\"Skype\" event=\"UserStatus(Status)\">\n";
    SkypeOnUserStatusChange += "var values = {\"StatusInfo\" : Status};\n";
    SkypeOnUserStatusChange += "var myArray = {\"key\" : \"Status\", \"values\" : values};\n";
    SkypeOnUserStatusChange += "var s=JSON.stringify(myArray);";
    SkypeOnUserStatusChange += "SkypeCallback(s,null);\n";
    SkypeOnUserStatusChange += "</script>";

this is my base user control (in short) so on each events callback is occur. (this can be change to any class it doesnt metter right now)

now i want to create custom controls that will show the data back from the client.

in my opinion, i can change the call back reference client script to the one that exist in the Child Control and register the child control to the events of the base control.

what do you think ?

thanks :)

Niv