Access hidden asp.net objects

T

tshad

How do you hide an asp.net object and still be able to access it?

I had my email in a session variable, but you can't access the session
variable from Javascript (I don't think - since Javascript is Client and
Session is Server).

I tried using the email that was on the page, but it was surrounded by a
Panel that had its visible property set to false - so anything inside of the
Panel was not on the page.

I also tried to set a variable:

<asp:Label ID="emailSave" Visible="false" runat="server"/>

But I had the same problem as the Panel, it wasn't on the page.

I am trying to access this from a page I open so this page is now the
opener.

How can I hide a variable and still get access to it via the Javascript?

Thanks,

Tom
 
P

Patrice

Not sure what you mean by "hidding". You can render this value as an hidden
field or by rendering dynamically created JavaScript so that this is usable
client side (in both cases "view source" will reveal the value).

What do you do with this value ? If you don't need this client side, just
retrieve this server side at will rather than passing this value to the
client just to postback the value to the server...
 
T

tshad

Patrice said:
Not sure what you mean by "hidding". You can render this value as an
hidden field or by rendering dynamically created JavaScript so that this
is usable client side (in both cases "view source" will reveal the value).

What do you do with this value ? If you don't need this client side, just
retrieve this server side at will rather than passing this value to the
client just to postback the value to the server...

I am trying to do this to get access from Javascript (clientSide) to my
variables on my parent page.

The problem is that if I do something like:

<asp:panel ID="EmailPanel" visible=false runat="server">
<asp:TextBox ID=Email runat="server"/>
</asp:panel>

or

<asp:Label ID="EmailSave" Visible=false/>

In either case, the variables do not seem to be on the page so JavaScript
can't see them.

I need this value to put onto the page that I am opening up.

Thanks,

Tom
 
T

tshad

Eliyahu Goldin said:
Server controls with Visible=false don't get rendered to client. Leave
Visible=true and hide with css rule display:none.

That worked great.

If I set the Panel display:none, will it work the same way and hide the
controls but leave them on the page?

Is there a way to set this from vb.net during processing?

I periodically set visible to false to hide a control or section of HTML
with controls on them. This is usually done by <Div id="something"
runat=false> or <asp:panel id = "something" runat=false> and then setting
something.visible=false.

This works pretty well most of the time.

But sometimes I do need to get access to the variables from Javascript - so
visible=false won't work.

So where I do something like this to hide panel in my asp.net code:

thePanel.visible = false

Is there a better way to do this so I can get access to the variables from
the panel?

How would I set style="display:none" from asp.net?

Thanks,

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


tshad said:
How do you hide an asp.net object and still be able to access it?

I had my email in a session variable, but you can't access the session
variable from Javascript (I don't think - since Javascript is Client and
Session is Server).

I tried using the email that was on the page, but it was surrounded by a
Panel that had its visible property set to false - so anything inside of
the Panel was not on the page.

I also tried to set a variable:

<asp:Label ID="emailSave" Visible="false" runat="server"/>

But I had the same problem as the Panel, it wasn't on the page.

I am trying to access this from a page I open so this page is now the
opener.

How can I hide a variable and still get access to it via the Javascript?

Thanks,

Tom
 
E

Eliyahu Goldin

If I set the Panel display:none, will it work the same way and hide the
controls but leave them on the page? Yes

How would I set style="display:none" from asp.net?
The easiest thing would be to make a css class

..Invisible{display:none}

Then you could set

something.CssClass="Invisible"

or

something.Attributes("class")="Invisible".

You also can do

something.Attributes("style")="display:none"
 
T

tshad

Eliyahu Goldin said:
The easiest thing would be to make a css class

.Invisible{display:none}

Then you could set

something.CssClass="Invisible"

or

something.Attributes("class")="Invisible".

You also can do

something.Attributes("style")="display:none"
That's what I needed to know.

Thanks,

Tom
 

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,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top