private void GenerateAjaxResponseScript() { StoreResponseData dataResponse = new StoreResponseData(); dataResponse.Data = this.Data != null?JSON.Serialize(this.Data) : this.JsonData; DataSourceProxy dsp = this.Proxy.Proxy as DataSourceProxy; if (dsp == null && this.Proxy.Proxy != null) { return; } dataResponse.TotalCount = dsp != null ? dsp.TotalCount : 0; Response response = new Response(true); response.Data = dataResponse.ToString(); this.AddScript(string.Concat(this.ClientID, ".callbackRefreshHandler(response, {serviceResponse: ", new ClientConfig().Serialize(response), "}, ", this.ClientID, ", o.eventType, o.action, o.extraParams);")); this.ajaxDataBindingRequired = false; }
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; }