HTML:
<ext:Button ID="UploadButton" runat="server" Text="文件上传" Icon="TableColumnAdd" > <DirectEvents> <Click OnEvent="UploadClick" Before="Ext.MessageBox.wait(‘‘, ‘上传中,请稍等...‘, { interval: 1000, duration: 50000, increment: 10, text: ‘上传中...‘, scope: this }); " Failure="Ext.Msg.show({ title : ‘错误‘, msg : ‘上传失败 minWidth: 200, modal : true, icon : Ext.Msg.WARNING, buttons : Ext.Msg.OK });" Timeout="30000"> </Click> </DirectEvents> </ext:Button>
或者
<ext:Button
ID="Button1"
runat="server"
Text="Click Me"
OnDirectClick="ButtonClick" />
C#:
protected void UploadClick(object sender, DirectEventArgs e) //函数是包含 object sender, DirectEventArgs e 两个参数的。
{ }
Example
<%@ Page Language="C#" %> <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %> <script runat="server"> protected void TestDirectEventHandler(object sender, DirectEventArgs e) { X.Msg.Alert("DirectEvent", e.ExtraParams.Count).Show(); } protected void AddParameter(object sender, DirectEventArgs e) { object p = new { name = "newParam", value = "newParam", }; X.Js.Call("addParameter", new JRawValue(Button1.ClientID), p); } </script> <!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>Ext.Net Example</title> <script type="text/javascript"> var onBefore = function (button, extraParams) { if (button.clickExtraParam) { extraParams[button.clickExtraParam.name] = button.clickExtraParam.value; } }; var addParameter = function (button, p) { if (!button.clickExtraParam) { button.clickExtraParam = {}; } button.clickExtraParam.name = p.name; button.clickExtraParam.value = p.value; }; </script> </head> <body> <form runat="server"> <ext:ResourceManager runat="server" /> <ext:Button ID="Button1" runat="server" Text="DirectEvent with ExtraParams"> <DirectEvents> <Click OnEvent="TestDirectEventHandler" Before="onBefore(this, extraParams)"> <ExtraParams> <ext:Parameter Name="someParam" Value="someParam" Mode="Value" /> </ExtraParams> </Click> </DirectEvents> </ext:Button> <ext:Button runat="server" Text="Add an extra parameter" OnDirectClick="AddParameter" /> </form> </body> </html>
原文:https://www.cnblogs.com/BinBinGo/p/11049497.html