Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Accessing invisible control in Javascript

Reply
Thread Tools

Accessing invisible control in Javascript

 
 
ipramod@gmail.com
Guest
Posts: n/a
 
      09-25-2007

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

 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      09-25-2007
Leave Visible=true and hide controls with a css style display:none.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
>
> 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
>



 
Reply With Quote
 
 
 
 
ipramod@gmail.com
Guest
Posts: n/a
 
      09-25-2007
Hey thanks...
it worked


On Sep 25, 7:50 pm, "Eliyahu Goldin"
<(E-Mail Removed)> wrote:
> Leave Visible=true and hide controls with a css style display:none.
>
> --
> Eliyahu Goldin,
> Software Developer
> Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
>
> <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed) ups.com...
>
>
>
>
>
> > 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- Hide quoted text -

>
> - Show quoted text -



 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      09-25-2007
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...

> Hey thanks...
> it worked


Just to add to Eliyahu's response, the reason that it worked (or, rather,
the reason that it didn't work with Visible="false") is because when you set
a control's Visible property to false server-side, it doesn't even get
downloaded to the client...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Control life cycle events not firing when control is invisible TS ASP .Net Building Controls 5 10-20-2008 09:10 PM
Making 1 control invisible while showing another in the exact location of the invisible one Andy B ASP .Net 5 05-29-2008 03:08 AM
Invisible - Succinic acid : (AMBER ACID) Invisible krithika.143@gmail.com C++ 0 04-14-2008 06:59 PM
Accessing invisible control in Javascript ipramod@gmail.com Javascript 1 09-25-2007 05:15 PM
Javascript call to invisible applet fails after upgrading to 1.5 (IE) Dag Sunde Java 8 05-10-2006 12:03 AM



Advertisments