Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JavaScript to Change Label Text in C#

Status
Not open for further replies.

Davidwe

Programmer
Jan 10, 2005
6
US
I am unable to clear or change text for a label created in C# using JavaScript. I am able to hide a text box and a drop down list.

Here is the function (placed in the head). The statement for the textbox works fine. The one for the label does not.
<script language="JavaScript>
function Test() { document.Form1.TextBox1.style.visibility="hidden"; document.Form1.Label1.text="";
alert('Changed');
}
</script>

Any suggestion? What should I use in place of Label1.text?

 
did you copy this code directly?

look at your script tag

<script language="JavaScript">

You're missing quotes.

Also: .text or .Text? Does JavaScript care?

Finally: Is this post in the right forum?
 
The missing quotes were probably from carelessly copying & pasting. I believe text should be lower case. I'm posting my question in several forums. My problem seems to be getting the JavaScript to access a label created in C#. That is why I'm posting here.

I did get the code to work using getElementById:
<script language="JavaScript">
function Test() {
document.Form1.TextBox1.style.visibility="hidden";
document.getElementById("Label1").innerText ="whoa!";
alert('Changed');
}
</script>
 
Perhaps this is the wrong forum, but I'll try it anway. Can anyone tell what is wrong with the code below? The statement setting txtSearch2 to "hidden" works. The one below it changing the lblDefine text to "ID" does not work. I know that the problem is how I am going about referencing the label. It should be similar to the code in the above post. Thanks for any help.

<script language="JavaScript">
function SetSearchIndexChanged()
{
if (window.document.Form1.MemberSearchControl1_ddListSearchFor.selectedIndex == 1)
window.document.Form1.MemberSearchControl1_txtSearch2.style.visibility = "hidden";
window.document.Form1.MemberSearchControl1.getElementById("lblDefine").innerText = "ID"; }
}
</script>
 
I case anyone is interested, here is the answer to my above question:

<script language="JavaScript">
function SetSearchIndexChanged()
if (window.document.Form1.MemberSearchControl1_ddListSearchFor.selectedIndex == 1)
{
window.document.Form1.MemberSearchControl1_txtSearch2.style.visibility = "hidden";
window.document.getElementById("MemberSearchControl1_lblDefine").innerText = "ID";
window.document.getElementById("MemberSearchControl1_lblDefine2").style.visibility = "hidden";
}
}
</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top