I recently had a situation where I needed to invoke a DirectEvent on an Ext.Net Button explicitly. Basically, when the button was clicked, I needed to pop-up an ExtJs window (created in javascript), and depending upon the options selected on the Window, invoke DirectEvents on various Ext.Net components rendered from server.
A bit of playing around with the javascript generated by the toolkit, and it was easy to figure out. It gets as simple as this for invoking a Button DirectClick:
{syntaxhighlighter brush: jscript;fontsize: 100; first-line: 1; }Ext.net.DirectEvent.confirmRequest({
control: #{btn1}
});{/syntaxhighlighter}
Here, you should pass the desired Button’s reference in the “control” parameter on which you need to invoke the DirectEvent.
To get a bit more complex, here’s how you would invoke DirectChange event for a TextField:
{syntaxhighlighter brush: jscript;fontsize: 100; first-line: 1; }Ext.net.DirectEvent.confirmRequest({
before: txt1Before(),
control: #{txt1},
action: ‘Change’
});{/syntaxhighlighter}
We did not pass “Click” for the action for Button, because that’s the default for Direct events (you can pass “action” as “Click” for button too if you want to). However, “control” is the only required config option to the confirmRequest method.
Other than that, there’s the required “control” reference on which the Direct Event has to be invoked, and the before method call, which if returns false, would cancel the invoking of the DirectEvent.
All other options for Ext.Net.DirectEvent that you specify through markup or in code-behind directly map to properties of the config object passed to the DirectEvent.confirmRequest method (if in doubt, check the javascript for the desired DirectEvent option generated by the toolkit).
An important point to remember is to invoke DirectEvents only on components rendered from server and which have event handlers defined in your server code. Trying to invoke DirectEvents on components instantized in javascript would raise server-side exceptions (which is obvious).
Attached is a sample file demonstrating invoking DirectEvents explicitly.
Recent Comments