Home > DeveloperSection > Forums > Change server side control's value in javascript function
jayprakash sharma
jayprakash sharma

Total Post:117

Points:821
Posted on    August-29-2014 1:13 AM

 JavaScript
Ratings:


 1 Reply(s)
 693  View(s)
Rate this:

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);");



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    September-01-2014 12:19 AM

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;

}


Don't want to miss updates? Please click the below button!

Follow MindStick