Ok, so I have been spinning my wheels on this one for a long time now, and as usual, i am sure that this is a really simple fix, so here goes…
I need to set a javascript variable using a variable from my code-behind file. Normally, I do it as follows:
var Test = <%= TestVar%>
On a normal page load, this method (while probably not the best way to do it) works great for me. The problem that I am now having, is that I need to change the variable on a callback with a callback/update panel. What I have, is the variable is set in a javascript block in the page header, and I then call a function that utilizes the variable on the callback panel’s EndCallback event.
var Var1 = <%= Var1%>;
function endCallback()
{
//some action with Var1;
}
Everything runs great, except that the server tag is not reloaded (because I am not doing a full page postback). Is there a better way to update a javascript variable on a partial postback?
If you want to change a server variable, you need an ajax call.
Using jquery or another method.
On server-side you need to create a method, maybe a web service. And then invoke it from the client-side sending the new value.
client side:
server-side: