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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change label text without submitting page

Status
Not open for further replies.

cawthor2

Programmer
May 2, 2002
10
0
0
US
This may be a stupid question, but is it possible to change a labels text value without submitting the page? I thought maybe you could do something like:

<asp:ImageButton id="ImageButton1" ImageUrl="images/graph.gif" OnClientClick="javascript: document.getelementbyid(Label1).text = 'Changed Text'; return false;" Runat="Server" />

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
 
so why doesn't this work?

<html>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ImageButton id="ImageButton1" ImageUrl="images/graph.gif" OnClientClick="javascript: document.getelementbyid('Label1').text = 'Changed Text'; return false;" Runat="Server" />

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>

It actually submits the page so I'm guessing the label assignment is failing. I looked in the source and it changes labels to <span> tags. I tried changing '.text' to '.innerhtml' but no avail.
 
document.getElementById('Label1').innerHtml
or
document.getElementByDd('Label1').innerHTML
can't remember which, but js is case sensative.

and like mark said, if your using user controls or master pages, then you need to render the client id, not the service id.

document.getElementById('<%=Label1.ClientID%>').innerHtml
or
document.getElementByDd('<%=Label1.ClientID%>').innerHTML



Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thank you!

document.getElementById('Label1').innerHTML worked for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top