Reputation: 1740
I have a variable named "tempVariable" in my jquery file. now I need to change its value from code behind in c#. What I have done till now is
in my C# code
public void changeValueInJquery()
{
bool newVal = false;
Page.ClientScript.RegisterClientScriptBlock(
GetType(),
"key", "ChangeValue(" + newVal + ");", true);
}
my jquery code is as
function ChangeValue(value1) {
alert(value1);
tempVariable = value1;
}
The issue is that ChangeValue() function never gets hit.
Am I going wrong somewhere?
Upvotes: 0
Views: 969
Reputation: 2148
may be '...'
is required to pass value...
Try this :
Page.RegisterStartupScript("changevalue", "<script>ChangeValue('" + newVal + "');</script>");
Upvotes: 1
Reputation: 21881
I would check in a JS debugger to see if you are getting any errors.
But generally try using Page.ClientScript.RegisterStartupScript();
instead if you are calling functions already present in the page. This will ensure that the script block is rendered at the bottom of the page and not for example before the ChangeValue function.
As other people have mentioned, this is nothing to do with jQuery.
Upvotes: 1