protected virtual void OnAjaxPostBack(BeforeDirectEventArgs e) { BeforeDirectEventHandler handler = (BeforeDirectEventHandler)Events[EventBeforeDirectEvent]; if (handler != null) { handler(this, e); } }
private void RaiseAjaxPostBackEvent(string eventArgument) { try { if (eventArgument.IsEmpty()) { throw new ArgumentNullException("eventArgument"); } string data = null; JToken parametersToken = null; if (this.DirectConfig != null) { parametersToken = this.DirectConfig.SelectToken("config.extraParams", false); JToken serviceToken = this.DirectConfig.SelectToken("config.serviceParams", false); if (serviceToken != null) { data = JSON.ToString(serviceToken); } } string action = eventArgument; BeforeDirectEventArgs e = new BeforeDirectEventArgs(action, data, parametersToken); this.OnAjaxPostBack(e); if (this.AutoDecode && data.IsNotEmpty()) { data = HttpUtility.HtmlDecode(data); } switch (action) { case "create": case "destroy": case "update": case "batch": if (data == null) { throw new InvalidOperationException("No data in request"); } this.DoSaving(action, data, parametersToken); break; case "read": StoreReadDataEventArgs refreshArgs = new StoreReadDataEventArgs(parametersToken); this.OnReadData(refreshArgs); PageProxy dsp = this.Proxy.Primary as PageProxy; if (dsp != null) { if (refreshArgs.Total > -1) { dsp.Total = refreshArgs.Total; } } break; case "submit": if (data == null) { throw new InvalidOperationException("No data in request"); } StoreSubmitDataEventArgs args = new StoreSubmitDataEventArgs(data, parametersToken); this.OnSubmitData(args); break; } } catch (Exception ex) { success = false; msg = this.IsDebugging ? ex.ToString() : ex.Message; if (this.ResourceManager.RethrowAjaxExceptions) { throw; } } AfterDirectEventArgs eAjaxPostBackResult = new AfterDirectEventArgs(new Response(success, msg)); this.OnAjaxPostBackResult(eAjaxPostBackResult); StoreResponseData response = new StoreResponseData(); if (eAjaxPostBackResult.Response.Success) { switch (eventArgument) { case "read": if (this.RequiresDataBinding) { this.DataBind(); } response.Data = this.GetAjaxDataJson(); PageProxy dsp = this.Proxy.Primary as PageProxy; response.Total = dsp != null ? dsp.Total : -1; break; case "create": case "destroy": case "update": response.Data = JSON.Serialize(this.responseRecords); break; } } eAjaxPostBackResult.Response.Data = response.ToString(); ResourceManager.ServiceResponse = eAjaxPostBackResult.Response; }
private void RaiseAjaxPostBackEvent(string eventArgument) { bool needConfirmation = false; try { if (eventArgument.IsEmpty()) { 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; BeforeDirectEventArgs e = new BeforeDirectEventArgs(action, data, parametersNode); this.OnAjaxPostBack(e); PageProxy dsp = this.Proxy.Proxy as PageProxy; if (this.AutoDecode && data.IsNotEmpty()) { data = HttpUtility.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.Total > -1) { dsp.Total = refreshArgs.Total; } } 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.ResourceManager.RethrowAjaxExceptions) { throw; } } AfterDirectEventArgs eAjaxPostBackResult = new AfterDirectEventArgs(new Response(success, msg)); this.OnAjaxPostBackResult(eAjaxPostBackResult); StoreResponseData response = new StoreResponseData(); if (needRetrieve && eAjaxPostBackResult.Response.Success) { if (this.RequiresDataBinding) { this.DataBind(); } response.Data = this.GetAjaxDataJson(); PageProxy dsp = this.Proxy.Proxy as PageProxy; response.Total = dsp != null ? dsp.Total : 0; } if (needConfirmation) { response.Confirmation = changingEventArgs.ConfirmationList; } eAjaxPostBackResult.Response.Data = response.ToString(); ResourceManager.ServiceResponse = eAjaxPostBackResult.Response; }
private void RaiseAjaxPostBackEvent(string eventArgument) { bool needConfirmation = false; try { if (eventArgument.IsEmpty()) { 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; BeforeDirectEventArgs e = new BeforeDirectEventArgs(action, data, parametersNode); this.OnAjaxPostBack(e); PageProxy dsp = this.Proxy.Proxy as PageProxy; if (this.AutoDecode && data.IsNotEmpty()) { data = HttpUtility.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.Total > -1) { dsp.Total = refreshArgs.Total; } } 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.ResourceManager.RethrowAjaxExceptions) { throw; } } AfterDirectEventArgs eAjaxPostBackResult = new AfterDirectEventArgs(new Response(success, msg)); this.OnAjaxPostBackResult(eAjaxPostBackResult); StoreResponseData response = new StoreResponseData(); if (needRetrieve && eAjaxPostBackResult.Response.Success) { if (this.RequiresDataBinding) { this.DataBind(); } response.Data = this.GetAjaxDataJson(); PageProxy dsp = this.Proxy.Proxy as PageProxy; response.Total = dsp != null ? dsp.Total : 0; } if (needConfirmation) { response.Confirmation = changingEventArgs.ConfirmationList; } eAjaxPostBackResult.Response.Data = response.ToString(); ResourceManager.ServiceResponse = eAjaxPostBackResult.Response; }