469,625 Members | 1,904 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

getElementById returning null value

Rob
Hi,

I have a label that I'm trying to make invisible on the client side using
the OnClientClick event for a button.

In the javascript function I have the following code:

var x = getElementById("ctl00_ContentPlaceHolder1_label");
x.Visible = true;

The function is being called correctly, but I can't get getElementId to
return anything other than NULL. We're using AJAX and I've tried calling the
script using label.ClientID from the server side using RegisterStartupScript
in the Page Load event on the server side. But the result is the same. I
checked the ClientID and it's definitely ctl00_ContentPlaceHolder1_label

I've also tried using get$ in place of getElementById, but the result is the
same.

It's not finding ctl00_ContentPlaceHolder1_label, but I don't know what else
it could be. Any advice would be appreciated.

Regards,

Jan 23 '08 #1
4 7293


"Rob" <r_******@ozemail.com.auwrote in message
news:uo**************@TK2MSFTNGP03.phx.gbl...
Hi,

I have a label that I'm trying to make invisible on the client side using
the OnClientClick event for a button.

In the javascript function I have the following code:

var x = getElementById("ctl00_ContentPlaceHolder1_label");
x.Visible = true;

The function is being called correctly, but I can't get getElementId to
return anything other than NULL. We're using AJAX and I've tried calling
the script using label.ClientID from the server side using
RegisterStartupScript in the Page Load event on the server side. But the
result is the same. I checked the ClientID and it's definitely
ctl00_ContentPlaceHolder1_label

I've also tried using get$ in place of getElementById, but the result is
the same.

It's not finding ctl00_ContentPlaceHolder1_label, but I don't know what
else it could be. Any advice would be appreciated.

Regards,
Have you inspected your HTML Source produced by your app ? Is the
"ctl00_ContentPlaceHolder1_label" element present ?
--
Gianluca Gravina
http://blogs.ugidotnet.org/thinkingingrava

Jan 23 '08 #2
Rob
Hi,

I've checked in the source and the element is not present. I have it
initially set to invisible. I tried setting it to visible intially and it
was in the source. If an invisible element does not appear in the source, I
don't know how I'm supposed to toggle it between visible and invisible on
the client side

Thanks.

"grava" <g_*******@hotmail.comwrote in message
news:AD**********************************@microsof t.com...
>

"Rob" <r_******@ozemail.com.auwrote in message
news:uo**************@TK2MSFTNGP03.phx.gbl...
>Hi,

I have a label that I'm trying to make invisible on the client side using
the OnClientClick event for a button.

In the javascript function I have the following code:

var x = getElementById("ctl00_ContentPlaceHolder1_label");
x.Visible = true;

The function is being called correctly, but I can't get getElementId to
return anything other than NULL. We're using AJAX and I've tried calling
the script using label.ClientID from the server side using
RegisterStartupScript in the Page Load event on the server side. But the
result is the same. I checked the ClientID and it's definitely
ctl00_ContentPlaceHolder1_label

I've also tried using get$ in place of getElementById, but the result is
the same.

It's not finding ctl00_ContentPlaceHolder1_label, but I don't know what
else it could be. Any advice would be appreciated.

Regards,

Have you inspected your HTML Source produced by your app ? Is the
"ctl00_ContentPlaceHolder1_label" element present ?
--
Gianluca Gravina
http://blogs.ugidotnet.org/thinkingingrava
Jan 23 '08 #3
Two things:

1. var x = getElementById("<%= label.ClientID %>"); looks much better

2. Likely the label has it's Visible property set to false/ If so, it is not
rendered to the client in the first place. Consider hiding with css rule
display:none.
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Rob" <r_******@ozemail.com.auwrote in message
news:uo**************@TK2MSFTNGP03.phx.gbl...
Hi,

I have a label that I'm trying to make invisible on the client side using
the OnClientClick event for a button.

In the javascript function I have the following code:

var x = getElementById("ctl00_ContentPlaceHolder1_label");
x.Visible = true;

The function is being called correctly, but I can't get getElementId to
return anything other than NULL. We're using AJAX and I've tried calling
the script using label.ClientID from the server side using
RegisterStartupScript in the Page Load event on the server side. But the
result is the same. I checked the ClientID and it's definitely
ctl00_ContentPlaceHolder1_label

I've also tried using get$ in place of getElementById, but the result is
the same.

It's not finding ctl00_ContentPlaceHolder1_label, but I don't know what
else it could be. Any advice would be appreciated.

Regards,

Jan 23 '08 #4
The Visible property is a server side property so. It it is false the
element is not rendered at all in the HTML page.

If you want to toggle this client side you could use a style (such as
visibility:hidden or display:none) and toggle this style value client
side...

--
Patrice

"Rob" <r_******@ozemail.com.aua écrit dans le message de news:
uj**************@TK2MSFTNGP03.phx.gbl...
Hi,

I've checked in the source and the element is not present. I have it
initially set to invisible. I tried setting it to visible intially and it
was in the source. If an invisible element does not appear in the source,
I don't know how I'm supposed to toggle it between visible and invisible
on the client side

Thanks.

"grava" <g_*******@hotmail.comwrote in message
news:AD**********************************@microsof t.com...
>>

"Rob" <r_******@ozemail.com.auwrote in message
news:uo**************@TK2MSFTNGP03.phx.gbl...
>>Hi,

I have a label that I'm trying to make invisible on the client side
using the OnClientClick event for a button.

In the javascript function I have the following code:

var x = getElementById("ctl00_ContentPlaceHolder1_label");
x.Visible = true;

The function is being called correctly, but I can't get getElementId to
return anything other than NULL. We're using AJAX and I've tried calling
the script using label.ClientID from the server side using
RegisterStartupScript in the Page Load event on the server side. But the
result is the same. I checked the ClientID and it's definitely
ctl00_ContentPlaceHolder1_label

I've also tried using get$ in place of getElementById, but the result is
the same.

It's not finding ctl00_ContentPlaceHolder1_label, but I don't know what
else it could be. Any advice would be appreciated.

Regards,

Have you inspected your HTML Source produced by your app ? Is the
"ctl00_ContentPlaceHolder1_label" element present ?
--
Gianluca Gravina
http://blogs.ugidotnet.org/thinkingingrava

Jan 23 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

24 posts views Thread by Robi | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.