Reputation:
I want to set Label's text in javascript function, function call and set text to Label and I see it but when I want to read Label's text from code behind the text is previous text (for example if label's text is "5" and I set it to "10" in function but in code behind text is "5")
Javascript function
function PopUpFunction(code) {
$("#<%= lblStatus.ClientID %>").text(code);
return false;
}
Set function to click event
of LinkButton
lnk.Attributes.Add("onclick", "PopUpFunction(10);");
Upvotes: 1
Views: 4645
Reputation: 38683
Are you any script file (Any minimized version) for (**<script type="text/javascript" src="../../Scripts/jquery-ui-1.9.2.min.js"></script>**)
is refering in your page head tag ?
Must add any minimized version script in your page . And first run your application in IE browser . let know Check the IE browser is threw any error ??
Upvotes: 0
Reputation: 9126
Reason for your code doesn't work
It happens because you call the JavaScript Function and it sets the Value but after that the page get reloads... So the Original Value Overwrite the New Value...
If you return False then it doesn't post back the Data and the Page doesn't get reload..
Try it like below... it will help you...
C#
lnk.Attributes.Add("onclick", "return PopUpFunction(10);");
Javascript :
<script>
function PopUpFunction(code) {
document.getElementById("lblStatus").innerHTML = code
return false;
}
</script>
Upvotes: 0
Reputation: 148150
You have used text as property but it is a function, Use text() not text
$("#<%= lblStatus.ClientID %>").text(code);
Put an alert to check if your page is refreshed or redirected
function PopUpFunction(code) {
$("#<%= lblStatus.ClientID %>").text(code);
alert($("#<%= lblStatus.ClientID %>").text());
}
You can try returning false to stop postback.
lnk.Attributes.Add("onclick", "return PopUpFunction(10);");
function PopUpFunction(code) {
$("#<%= lblStatus.ClientID %>").text(code);
alert($("#<%= lblStatus.ClientID %>").text());
return false;
}
Upvotes: 4