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

User control and clientside script - content of asp:label

Status
Not open for further replies.

IlseDC

Programmer
Mar 24, 2003
49
0
0
BE
I made a user control and in this user control I have some clientside script (Page.RegisterClientScriptBlock in the page_load of the user control).
In this script I want to know the content of an ASP-label.

for example:
<asp:label id=lblText runat="server"></asp:label>.

How can I get the content of label lblText in clientside script (javascript)?

I do not know the name of the form on which the user control is.

Thanks.
 
Try using the document.getElementById method of javascript.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
getElementById does not work.

I tried this:

strScript = "<SCRIPT LANGUAGE='JavaScript'>"
+ "function Test()"
+ "{"
+ "alert(document.getElementById('lblText').value);"
+ "}"
+ "</SCRIPT>";
Page.RegisterClientScriptBlock("TestRoutine", strScript);
 
The reasons that getElementById does not work in your example are:

1) The script is written out to the page but nothing actually executes it
2) I'm presuming that by the name of the id you are lookng for , it is an ASP label control that you have used. If it is, then this is written out to the page as a <span> element and therefore it doesn't actually have a value e.g.

From the View Source, you will see:
Code:
<span id="Label1">Label</span>
instead of:
Code:
<span id="Label1" value="Label">Label</span>


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top