Reputation: 2237
we are store asp.net html table in session ,its working file with InProc session state.
while we use stateserver then there there is issue to serialization to get table object from session.
i have try with belo code not able to get it done...
Table table = null;
Session["table"] = tableToJson(table);
table = jsonToTable(Session["table"]);
private string tableToJson(Table obj)
{
//Formatting.Indented, new JsonSerializerSettings() {ReferenceLoopHandling = ReferenceLoopHandling.Serialize}
// return JsonConvert.SerializeObject(obj,Formatting.Indented, new JsonSerializerSettings() {ReferenceLoopHandling = ReferenceLoopHandling.Serialize});
//return JsonConvert.SerializeObject(obj);
// return JsonConvert.SerializeObject(obj, Newtonsoft.Json.Formatting.Indented, new JsonSerializerSettings() { PreserveReferencesHandling = PreserveReferencesHandling.All });
StringBuilder sb = new StringBuilder();
HtmlTextWriter tw = new HtmlTextWriter(new StringWriter(sb));
obj.RenderControl(tw);
return tw.InnerWriter.ToString();
}
private Table jsonToTable(object obj)
{
string serializedData = (string)obj;
serializedData = serializedData.Replace("<table", "<table runat=\"server\"");
Control tbl = Page.ParseControl(serializedData);
return tbl as Table;
//var serializer = new XmlSerializer(typeof(Table));
//var reader = new XmlTextReader(new StringReader(serializedData));
//return (Table)serializer.Deserialize(reader);
//string o = (string)obj;
//Table tbl = (Table)Newtonsoft.Json.JsonConvert.DeserializeObject(o, typeof(Table));
//return tbl;
}
also see thanks
Upvotes: 0
Views: 228