getElementById returning null value
getElementById returning null value
am 23.01.2008 10:35:20 von 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,
Re: getElementById returning null value
am 23.01.2008 10:51:42 von grava
"Rob" wrote in message
news:uowmpRaXIHA.3956@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
Re: getElementById returning null value
am 23.01.2008 11:08:36 von 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" wrote in message
news:AD76A44D-C88A-4E2F-9098-C24674C09BAA@microsoft.com...
>
>
> "Rob" wrote in message
> news:uowmpRaXIHA.3956@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
Re: getElementById returning null value
am 23.01.2008 11:21:04 von Eliyahu Goldin
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" wrote in message
news:uowmpRaXIHA.3956@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,
>
Re: getElementById returning null value
am 23.01.2008 11:28:45 von Patrice
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" a écrit dans le message de news:
ujZUUkaXIHA.5784@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" wrote in message
> news:AD76A44D-C88A-4E2F-9098-C24674C09BAA@microsoft.com...
>>
>>
>> "Rob" wrote in message
>> news:uowmpRaXIHA.3956@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
>