Accessing invisible control in Javascript

I

ipramod

Hi All,

I have below label which is invisible when the page loads.
<asp:Label ID="lblTest" runat="server" Visible="false" Text="Test"></
asp:Label>

Now if I want to make this label visible on the web page, I used below
javascript:
document.getElementById("<%= lblTest.ClientID %>").style.display =
"block";


But when the Javascript code is executed, I get below exception:
"Object required"

As per my observation, if the control is not loaded at the first time
then it will not have the client id and it will throw an exception.

Same is the case with DIV. I have 2 DIV's which are invisible on the
page load and in special cases I want to make one DIV visible and make
other invisible then I get the above exception.

So, is there any way to make the controls visible/invisible regardless
of their initial stage?

Please let me know ASAP.

Thanks in advance,
PI
 
H

Henry

(e-mail address removed) said the following on 9/25/2007 10:25 AM:

That isn't a label, it is server side code to generate a label
and your server side code is irrelevant.


Post what the browser gets and not your ASP code and it would be a lot
easier to tell you what is wrong with it.
<snip>

Assuming it is not a matter of timing (calling getElementById before
the HTMP parser has seen the relevant HTML mark-up) my suspicion would
be that this server side code is making the - Visible="false" - state
manifest by not outputting any HTML in that state. That would
certainly stop getElementById from finding any corresponding IDed
elements in the DOM. Obviously the confirmation of that suspicion
still involves looking at the HTML as generated by the server rather
than the code that does the generation.

An if there is no mark-up being sent when - Visible="false" - then no
amount of javascript will make it visible on the client.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top