CHANGE SERVER SIDE CONTROL'S VALUE IN JAVASCRIPT FUNCTION

jayprakash sharma

Total Post:117

Points:821
Posted by  jayprakash sharma
 990  View(s)
Ratings:
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);");

  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: Change server side control's value in javascript function

    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;

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!