Hugo Woesthuis Hugo Woesthuis - 2 months ago 12
JSON Question

Is it possible to programmatically execute JSON queries with C# (ASP.NET)

As the title says: is it possible?

You should think of the following scenario: I press a button in ASP.NET -> some C# backend -> Execute a JSON string

So something like this:

protected void Unnamed1_Click(object sender, EventArgs e)
{
string check = (string)(Session["usr"])

if(check == null;)
{
// Execute JSON
}
else
{
Response.Redirect("~/Home.aspx");
}
}


Does anyone know how to do this?

Thanks in advance.

Answer

You need to use this method

RegisterStartupScript(scriptname, jsonstring);

This will put the script on top of the html page. Further read: https://msdn.microsoft.com/en-us/library/system.web.ui.page.registerstartupscript(v=vs.110).aspx