Not sure if this was the best forum but I'm trying to Stringify my search criteria and pass it as a parameter to an UpdatePanel as follows:
__doPostBack('ctl00$ContentPlaceHolder1$upSearchResults', JSON.stringify(data));
NOTE: the JSON data being passed above looks like json below when I call stringify(). The "data" object is a nested object with searchType and a list of company objects ( It contains the type of search and the companies to search for)
JSON.stringify(data) ...
"{"searchType":"Company","companyList":[{"CompanyId":"36492","CompanyName":"ABC INC","Ticker":ABC},{"CompanyId":"37497","CompanyName":"ACME & CO","Ticker":ACME}]}"
However, when I recieve it on the server it looks like:
string data = Request.Params.Get("__EVENTARGUMENT");
data...
"{\"searchType\":\"Company\",\"companyList\":[{\"CompanyId\":\"36492\",\"CompanyName\":\"CATERPILLAR INC\",\"Ticker\":null},{\"CompanyId\":\"37497\",\"CompanyName\":\"DEERE & CO\",\"Ticker\":null}]}"
I can't seem to deserialize it into a C# class...neither calls below to Deserialize work....
System.Web.Script.Serialization.JavaScriptSerializer json = new System.Web.Script.Serialization.JavaScriptSerializer();
List<SearchCriteria> searchCriteria= json.Deserialize<List<SearchCriteria>>(data)
SearchCriteria criteria = json.Deserialize<SearchCriteria>(data);
The classes are below...
[Serializable]
public class SearchCriteria {
string searchType { get; set; }
List<Company> companyList { get; set; }
}
[Serializable]
public class Company {
public string CompanyId { get; set; }
public string CompanyName { get; set; }
public string Ticker { get; set; }
}