protected virtual void OnAjaxPostBackResult(AfterAjaxEventArgs e) { AfterAjaxEventHandler handler = (AfterAjaxEventHandler)Events[EventAfterAjaxEvent]; if (handler != null) { handler(this, e); } }
public void RaiseAjaxPostBackEvent(string eventArgument, ParameterCollection extraParams) { bool success = true; string msg = null; TreeNodeCollection nodes = null; try { if (string.IsNullOrEmpty(eventArgument)) { throw new ArgumentNullException("eventArgument"); } switch (eventArgument) { case "nodeload": NodeLoadEventArgs e = new NodeLoadEventArgs(extraParams); PageTreeLoader loader = (PageTreeLoader)this.Loader.Primary; loader.OnNodeLoad(e); nodes = e.Nodes; success = e.Success; msg = e.ErrorMessage; break; } } catch (Exception ex) { success = false; msg = this.IsDebugging ? ex.ToString() : ex.Message; if (this.ScriptManager.RethrowAjaxExceptions) { throw; } } AfterAjaxEventArgs eAjaxPostBackResult = new AfterAjaxEventArgs(new Response(success, msg)); eAjaxPostBackResult.Response.Data = nodes != null?nodes.ToJson() : null; ScriptManager.ServiceResponse = eAjaxPostBackResult.Response; }
private void RaiseAjaxPostBackEvent(string eventArgument) { bool needConfirmation = false; try { if (string.IsNullOrEmpty(eventArgument)) { throw new ArgumentNullException("eventArgument"); } XmlNode xmlData = this.SubmitConfig; string data = null; XmlNode parametersNode = null; if (xmlData != null) { parametersNode = xmlData.SelectSingleNode("config/extraParams"); XmlNode serviceNode = xmlData.SelectSingleNode("config/serviceParams"); if (serviceNode != null) { data = serviceNode.InnerText; } } string action = eventArgument; BeforeAjaxEventArgs e = new BeforeAjaxEventArgs(action, data, parametersNode); this.OnAjaxPostBack(e); DataSourceProxy dsp = this.Proxy.Proxy as DataSourceProxy; if (this.AutoDecode && !string.IsNullOrEmpty(data)) { data = this.Page.Server.HtmlDecode(data); } switch (action) { case "update": if (data == null) { throw new InvalidOperationException("No data in request"); } needConfirmation = this.UseIdConfirmation; this.DoSaving(data, parametersNode); if (this.RefreshAfterSaving == RefreshAfterSavingMode.None || dsp != null) { needRetrieve = false; } break; case "refresh": needRetrieve = true; StoreRefreshDataEventArgs refreshArgs = new StoreRefreshDataEventArgs(parametersNode); this.OnRefreshData(refreshArgs); if (dsp != null) { if (refreshArgs.TotalCount > -1) { dsp.TotalCount = refreshArgs.TotalCount; } } break; case "submit": needRetrieve = false; if (data == null) { throw new InvalidOperationException("No data in request"); } StoreSubmitDataEventArgs args = new StoreSubmitDataEventArgs(data, parametersNode); this.OnSubmitData(args); break; } } catch (Exception ex) { success = false; msg = this.IsDebugging ? ex.ToString() : ex.Message; if (this.ScriptManager.RethrowAjaxExceptions) { throw; } } AfterAjaxEventArgs eAjaxPostBackResult = new AfterAjaxEventArgs(new Response(success, msg)); this.OnAjaxPostBackResult(eAjaxPostBackResult); StoreResponseData response = new StoreResponseData(); if (needRetrieve && eAjaxPostBackResult.Response.Success) { if (this.RequiresDataBinding) { this.DataBind(); } response.Data = this.Data != null?JSON.Serialize(this.Data) : this.JsonData; DataSourceProxy dsp = this.Proxy.Proxy as DataSourceProxy; response.TotalCount = dsp != null ? dsp.TotalCount : 0; } if (needConfirmation) { response.Confirmation = changingEventArgs.ConfirmationList; } eAjaxPostBackResult.Response.Data = response.ToString(); ScriptManager.ServiceResponse = eAjaxPostBackResult.Response; }