Changing LABEL value by JQuery or Javascript does not work in ASP.NET

3

I use this JS function in ASP.net:

function habilitado(){
    var b = document.getElementById('<%= Label4.ClientID %>').value = "Habilitado";
}

I call it that in codebehind. The label value should be changed, but this does not happen. Can anyone help?

Note: I have already tried $(document).ready(function() at the beginning, and it still does not work.

ClientScript.RegisterClientScriptBlock(this.GetType(), "teste", "<script language=\"javascript\">habilitado();</script>");
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "teste", "<script type='text/javascript'>habilitado();</script>", true);
    
asked by anonymous 15.03.2014 / 21:45

3 answers

5

The value option is not applicable for labels. Try switching to innerHTML . So:

document.getElementById('<%= Label4.ClientID %>').innerHTML = "Habilitado";

    
15.03.2014 / 22:04
1

With jQuery it can be done like this:

$('#<%= Label4.ClientID %>').html("Conteúdo novo...");
    
15.03.2014 / 22:59
1

The .value f% of javascript is only useful in elements <input /> and the .innerHTML should be used when you want to get / modify the internal content of some element, such as div's, label's and span's.

Sources:

link link

    
17.03.2014 / 13:10