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

Asked

Viewed 3,820 times

3

Use this JS function in ASP.net:

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

I call it that in codebehind. The value of the label should be changed, but it doesn’t happen. Someone can help?

Note: I’ve tried using $(document).ready(function() at first, and yet it doesn’t 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);
  • When you load the page in the browser, does the generated Javascript look like this? Have you checked if the first string ('<%= Label4.ClientID %>') replaced by label ID?

3 answers

5


The option value is not applicable for Abels. Try to exchange for innerHTML. Thus:

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

1

1

With jQuery can be done so:

$('#<%= Label4.ClientID %>').html("Conteúdo novo...");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.