I have javascript getter setter class
function UserContext() {
var category_id;
var biller_id;
this.get_category_id = function () {
return category_id;
}
this.set_category_id = function (value) {
category_id = value;
}
this.get_biller_id = function () {
return biller_id;
}
this.set_biller_id = function (value) {
biller_id = value;
}
}
I am creating object of this class in jquery
click event
var contextObj = new UserContext();
contextObj.set_category_id('SOME VALUE');
contextObj.set_biller_id('65');
I have similar class in c#
public class CustomerDTO
{
public string category_id { get; set; }
public string biller_id{ get; set; }
}
And one asp:hidden
element
<asp:HiddenField ID="hdnValue" ClientIDMode="Static" runat="server" />
What i want to achieve
- Assign
contextObj
toasp:hidden
element by serializing (may be in json format) - In Code behind get this object desrailize it and assign the values to its respective c# class i.e
CustomerDTO
- So that i can access all these values through out all pages request (By Passing this object in Server.Transfer request)
To serialize object i tried this
console.log(JSON.stringify(contextObj));
But it prints nothing. I want value to get printed so that i can assign to hidden variable