Skip to content

Instantly share code, notes, and snippets.

@JohnBaek
Last active June 28, 2016 07:44
Show Gist options
  • Save JohnBaek/d195f78a3f69c6bcc2a3ce8a9ba3f1e8 to your computer and use it in GitHub Desktop.
Save JohnBaek/d195f78a3f69c6bcc2a3ce8a9ba3f1e8 to your computer and use it in GitHub Desktop.
C#_Ajax_Responsing_In_WebForms.cs
using System;
using System.Net;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Script.Serialization;
namespace NameSpace
{
public partial class Ajax : System.Web.UI.Page
{
private object wrap;
protected void Page_Load(object sender, EventArgs e)
{
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
string json = new JavaScriptSerializer().Serialize(this.wrap);
Response.Write(json);
}
#region @Binding user rquest to method and inject common return Object
private void ajaxRequestTriger(string _request) {
switch (_request) {
case "req": reqT(); break;
}
}
#endregion
public void reqT() {
}
#region @Parameter binding in user Request
private void setRequestParams()
{
}
#endregion
#region @Convert DataSet Object to List<Dictionary<string, object>>
private List<Dictionary<string, object>> getJsonForDataSet(DataSet ds)
{
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
Dictionary<string, object> row;
string Excep = string.Empty;
try
{
if (ds.Tables.Count > 0)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
row = new Dictionary<string, object>();
foreach (DataColumn col in dr.Table.Columns)
{
row.Add(col.ColumnName, dr[col].ToString());
}
rows.Add(row);
}
}
}
catch (Exception ex)
{
}
return rows;
}
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment