PDA

View Full Version : [CLOSED] Direct Event arguments on server side



anup
Aug 06, 2012, 5:27 PM
Hi,

I've been following various suggestions over the years on how to create custom components with custom listeners. Until now I've not really needed custom direct events, but for the book for completeness of a custom component I am showing a custom direct event. In doing so, I just wanted to double check something:

Listeners on the JavaScript side may have various event arguments and that all works as one would expect. For the corresponding Direct Event, however, for some reason I have been expecting some Ext.NET magic that when the direct event is invoked, any defined event arguments are automatically sent and made available in the DirectEventArgs of the handler.

For example, looking at the Ext.NET Source Code, I can see ListenerArgument attributes being used for your DirectEvents, too. But when I look at Firebug I do not see those arguments being submitted as part of the Direct Event.

For Direct Events, even if I want the *default* event arguments submitted, I have to manually set that up in the ExtraParams collection of the Direct Event, it seems.

For example, I took the simple array:
http://examples2.ext.net/#/GridPanel/ArrayGrid/Simple/

I added a DirectEvent:



<DirectEvents>
<Select OnEvent="GridPanel1_Select" />
</DirectEvents>


and it is defined like this:



protected void GridPanel1_Select(object sender, DirectEventArgs e)
{
// my code here
}


When I look at the e args, or FireBug, I don't see the additional parameters defined for the Select event in there. However, I can manually send them as extra parameters, (or if it is part of a form post and it is set up right I can look at other properties of the Grid on the server, if needed).

So it is not a problem as such, but I just wanted to double check, that is all correct and I didn't missed something?

I guess the reason the ListenerArgument attributes are seen on the Direct Event declarations in the source code (at least the ones I looked at) are probably related to the dynamic generation of some of your classes?

I observe this in both Ext.NET 1.x and 2.x

Thanks!

Daniil
Aug 06, 2012, 6:04 PM
Hi Anup,

Well, common DirectEvents can't pass any additional parameters to server itself. ListenerArguments are for client only - it means arguments which client side part of the DirectEvent will be called with.

Server

If you need special properties in DirectEventArgs to access any additional parameters you definitely should to extend the DirectEventArgs class getting the respective things from ExtraParams and use that class in your custom class.

Client

Any extra parameters should be sent from client. We would suggest to inherit the ComponentDirectEvent class overriding its ExtraParams property. So, it all can be implemented on server.


By the way, there is some example of such DirectEvent - Store OnReadData. The server part is implemented inStoreReadDataEventArgs (though it inherits directly EventArgs, not as I suggested before). And client part is implemented in PageProxy. I.e. PageProxy calls that OnReadData DirectEvent and manages its parameters. Though it is a bit complicated example for the beginning.

If you will be in trouble to implement the suggested things above, please request a sample.

anup
Aug 06, 2012, 8:25 PM
If you will be in trouble to implement the suggested things above, please request a sample.

Many thanks. No, shouldn't need sample (for now!) so you can mark as closed.