In c# code behind i am creating an object and try to access that in front-end javascript. but it is always getting instantiate value but not the object value; Please see the code below:
public class Product
{
public String[] Sizes { get; set; }
public decimal Price { get; set; }
public DateTime Expiry { get; set; }
public string Name { get; set; }
}
public partial class _Default : System.Web.UI.Page
{
public string sJSON = "shuvra";
public JavaScriptSerializer javaSerial = new JavaScriptSerializer();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Btn2_Click(object sender, EventArgs e)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
Product product = new Product
{
Name = "Apple",
Expiry = new DateTime(2008, 12, 28),
Price = 3.99M,
Sizes = new[] { "Small", "Medium", "Large" }
};
var oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
sJSON = oSerializer.Serialize(product);
JavaScriptSerializer ser = new JavaScriptSerializer();
//ser.Serialize(arrayMarker, jasonSerialize);
sb.AppendLine("markicons();");
ScriptManager.RegisterStartupScript(up_IFASelected, typeof(UpdatePanel), this.ClientID + "_LoadMap", sb.ToString(), true);
}
}
The javascript code:
function markicons() {
initialize();
var a = JSON.parse('<%= this.javaSerial.Serialize(this.arrayMarker) %>');
var b = eval('<%=this.sJSON%>');
}
The value 'b' is always shuvra but not the assigned value. How can i fix it?