此示例演示DirectEvent中定义的事件Before、After、Success、Failure、Complete执行顺序
这些事件是JS方法定义。以此执行的顺序是:1、Before 2、After 3、有异常或操作不成功Failure否则Success 4、Complete
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EvnetOrder.aspx.cs" Inherits="Events_DirectEvents_EvnetOrder" %> <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>事件执行顺序</title> <script runat="server"> protected void CheckAuthor(object sender, DirectEventArgs e) { string author = e.ExtraParams["author"]; if (author != "老虞") { e.ErrorMessage = "笔者不是老虞,而是" + author; e.Success = false; } else { //添加信息到客户端 Ext.Net.Parameter parameter = new Ext.Net.Parameter(); parameter.Name = "serverTime"; parameter.Value = DateTime.Now.ToLongDateString(); e.ExtraParamsResponse.Add(parameter); StringBuilder msg = new StringBuilder(); for (int i = 0; i < e.ExtraParams.Count; i++) { msg.AppendFormat("{0}={1}<br/>", e.ExtraParams[i].Name, e.ExtraParams[i].Value); } X.MessageBox.Notify(new NotificationConfig() { Icon = Icon.ApplicationHome, Title = "服务器:笔者信息", Html = msg.ToString() }).Show(); } } </script> <script type="text/javascript"> var index=0; var afterMethod=function(element,extraParams) { index++; var params =extraParams || {}; var msg="Author:"+params.author+"<br/>"; msg+="BLog:<a target='_blank' href='"+params.blog+"'>"+params.blog+"</a><br/>"; msg+="Time:"+params.time; Ext.net.Notification.show({ title:'afterMethod Index='+index, html:msg}); } var beforeMethod=function(el,type,action,extraParams) { index++; Ext.net.Notification.show({ title:'Before Index='+index, html:""}); } var failureMethod=function(response,result,control,type,action,extraParams) { index++; Ext.net.Notification.show({ title:'failureMethod Index='+index, html:result.errorMessage}); } var successMethod=function(response,result,control,type,action,extraParams) { index++; Ext.net.Notification.show({ title:'successMethod Index='+index, html:result.extraParamsResponse.serverTime}); } var completeMethod=function(success, response, result, control, type, action, extraParams) { index++; Ext.net.Notification.show({ title:'completeMethod index='+index, html:success.toString()}); } </script> </head> <body> <form id="form1" runat="server"> <ext:ResourceManager ID="ResourceManager1" runat="server"> </ext:ResourceManager> <ext:TextField ID="txtAuthor" runat="server" FieldLabel="笔者" Text="老虞" /> <ext:Button ID="Button1" runat="server" Text="提交"> <DirectEvents> <Click Failure="failureMethod" After="afterMethod" Before="beforeMethod" Complete="completeMethod" Success="successMethod" OnEvent="CheckAuthor" CleanRequest="false"> <ExtraParams> <ext:Parameter Name="author" Value="txtAuthor.getValue()" Mode="Raw" /> <ext:Parameter Name="blog" Value="http://www.cnblogs.com/howdo" Mode="Value" /> <ext:Parameter Name="time" Value="new Date()" Mode="Raw" /> </ExtraParams> </Click> </DirectEvents> </ext:Button> </form> </body> </html>这里可以通过查看Index的值判断方法执行顺序。 点击提交按钮,显示结果如下:
![未命名 未命名](https://images.cnblogs.com/cnblogs_com/howDo/201105/201105072020211382.png)