Dear All:
My project is winform, and I recently hope to use json.net to replace the viewstate using in gridview, like following:
[Serializable]
public class MyDataForm
{
public string LocationCode { get; set; }
public string ProjectNo { get; set; }
public string PatientName { get; set; }
public string PersonID { get; set; }
public string PdfURL { get; set; }
public string Memos { get; set; }
}
public List<MyDataForm> MyDataList { set { ViewState["MyDataList"] = value; } get { return ViewState["MyDataList"] as List<MyDataForm>; } }
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.EditIndex = -1;
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = MyDataList;
GridView1.DataBind();
}
I hope to store the data in HiddenField, and then catch the data back via JsonConvert.DeserializeObject<MyDataForm>( $("#hiddenFieldID").val()) when post back each time.
The main problem is come from when to replace viewstate in ASP life cycle.
In which stage, like Page_init, the gridview will call databind(), and if I can put the data which deserialize by Json in datasource,
And then I think it can replace viewstate completely, is anyone know how to make that, thanks a lot.