0

I set a javascript function to click event of LinkButton and want to set Label's text in this function,function call and pass data to it but after that when i want to read text of that Label from code behind,text is ""

//javascript function
function PopUpFunction(code) {
$("#<%= lblStatus.ClientID %>").text = code;
}

//set function to click event
lnk.Attributes.Add("onclick", "PopUpFunction(10);");

//Edit

I test Label (lblStatus) when i click on link button that call javascript's function,the text of label change but in code behind doesn't show this text (for example if text of label is 5 after i set new text in javascript's function again in code behind text is 5 although actual text is 10)

2
  • Please run your application in IE browser . please check any error threw in this line ?? Commented Mar 30, 2013 at 12:47
  • You should use firebug or chrome to debug this. Add some console.log statements to determine that code actually contains a value. The proper statement though is .text(code). Also, you'll want to test that the control you're accessing (lblStatus) is the proper control and the ID being produced is accurate. Commented Mar 30, 2013 at 12:57

7 Answers 7

1

Instead of Label use HiddenField and change javascript's function like below

function PopUpFunction(code) {
  $("#<%= lblStatus.ClientID %>").val(code);
  return false;
}
Sign up to request clarification or add additional context in comments.

Comments

1

It works for me. please check it out.

Code Behind: little modification

   ` lnk.Attributes.Add("onclick", "return PopUpFunction('10');");

Javascript code

  `<script type="text/javascript">
    function PopUpFunction(code) {
        $("#lblStatus").text(code);
        $("#lblStatus").show();
        return false;
    }
</script>

3 Comments

is it working for you or not? please let me know. keep updating.
then there should be some other errors on client side. otherwise this code is working fine on my machine. Please check the error console in Mozilla by using the key combination "Ctrl+Shift+j". It'll show you the client side errors in your code. please try it.
please provide the whole code. Once i faced the same problem. please show us your code behind and html part.
0

PopUpFunction(10) function is taking 10 as an integer datataype so your calling function does not get anything.Convert it or pass it as a string then you will get correct output

3 Comments

plz explain what should i do now?
try to call function as below: lnk.Attributes.Add("onclick", "PopUpFunction("Some_Text");");
JavaScript shouldn't care about this. It should handle the types dynamically.
0

try this val() instead of text

$("#<%= lblStatus.ClientID %>").Val(code) ;

or ,Change text() instead of text

$("#<%= lblStatus.ClientID %>").text()=code 

4 Comments

your syntax is incorrect...$("#<%= lblStatus.ClientID %>").val(code);
i set $("#<%= lblStatus.ClientID %>").text(code); , $("#<%= lblStatus.ClientID %>").val(code); but again text is ""
please Run your application in IE browser . please check any error threw in this line ??
Put debugger in your js code .then please check code parameter value
0

try something like this:

document.getElementById('The Control ID').InnerHTML = 'YourText'; 

example: Label1

document.getElementById('Label1').InnerHTML = 'Hello World!'; 

Comments

0
lnk.onclick = function(){
    PopUpFunction('Some_Text'); 
});

Comments

0

try the following

 function PopUpFunction(code) {
    $("#<%= lblStatus.ClientID %>").val(code);
    }

while getting it's value use this

string str=Request.Form(lblStatus.UniqueID);

3 Comments

syntax is incorrect. Form is property buy you use it as method
take a hidden field ...set value in that and get value from hidden field...this will definitely work
I don't understand,plz explain

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.