Looking to pass variables from c# to javascript to use some jquery code. Passing doubles, ints, strings, arrays. Does anyone know how to do this?
for example if I ha
I recently used this ToJson() extension method along with Page.RegisterClientScriptBlock Method to pass down a multi-level mapping object that populates three levels of cascaded dropdowns.
Nevermind I think I figured it out. Assuming the code above, you can write in javascript:
<script type="text/javascript"> var JavascriptBlah = '<%=blah%>'</script>
This will pass the blah in c# to the JavascriptBlah on the client side. Then you can manipulate on client side.
you can use asp:HiddenField variables to pass values between codebehind and js.. this accomplished with viewstate of page during postbacks...
You need this(How Do I: Add JavaScript to An ASP.NET Page), I guess?
You can use public properties on the code behind as well as the session. Here is a sample using public properties that can be read from a Javascript function.
Front End:
function IsAgentInProgram()
{
var optStatus = "<%=AgentOptInStatus%>";
if (optStatus == "True")
alert("You are opted in!");
else
alert ("You are opted OUT");
}
Code Behind:
public bool AgentOptInStatus;
private void Page_Load(object sender, System.EventArgs e)
{
this.AgentOptInStatus = true;
}