Click here to Skip to main content
15,892,517 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all
since last 8 hours i am asking one simple question but no one could help me out
i have 2 asp controls on page
button
label
when user clicks button then label value should be changed to any other value and label has a default value of "Label1"
i want to achieve this task using jquery i have tried different things but nothing happened u can see them in comments below
JavaScript
<head>
<script type="text/javascript">
 $(document).ready(function() {
        $("#Button5").click(function() {
        $("#Label1").html = "change";
        //$("#Label1").innerHTML ="hello word";
            alert("Hello world!");
        });
        });
 // $(document).ready(function() {
       //if($("#Label1").html()=="Label"){
	 ///ll('Label1').innerHTML ="hello word"
	//"#Label1".html()=="l1";
		//$("#popupCon").css("opacity","0.7");
       //} 
       
        
    </script>
</head>

and alert function is working perfectly
please help me
thanks
Posted
Comments
tanweer 30-May-12 6:17am    
I have edited the below answer and it will definitly work and there is no doubt of error. please try now
mehdilahori 30-May-12 6:47am    
hi tanweer
i tried this before and this will work because of alert method or function but when we remove alert line this will not work
and the reason of this is that error is happening because of postbackif a PostBack occurs, the Label will revert to the original, since Labels changed client-side are not persisted in ViewState. so how can i achieve this after post back is occurred i have diagnosed the error but could not find the treatment
your views on this
thanks
tanweer 30-May-12 7:24am    
if there is nothing on the serverside on the Button click event then please call the javascript like this.
function ChangeText(){
$("#Label1").html("change");
return false;
}

and the button will look like this:
<asp:Button ID="button1" runat="server" Text="Change Text" OnClientClick="return ChangeText();" />

this will call the javascript method but will not get a postback.
best of luck

1 solution

Try this

XML
<script type="text/javascript">
 $(document).ready(function() {
        $("#Button5").click(function() {
        $("#Label1").html("change");       
            alert("Hello world!");
        });
        });
    </script>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900