Skip to content Skip to sidebar Skip to footer

Change Server Side Control's Value In Javascript Function

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

Solution 1:

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

functionPopUpFunction(code) {
  $("#<%= lblStatus.ClientID %>").text(code);
  alert($("#<%= lblStatus.ClientID %>").text());
  returnfalse;
}

Solution 2:

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>functionPopUpFunction(code) {
           document.getElementById("lblStatus").innerHTML = code
           returnfalse;
       }
   </script>

Solution 3:

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 ??

Post a Comment for "Change Server Side Control's Value In Javascript Function"