Access hidden asp.net objects

Discussion in 'ASP .Net' started by tshad, Sep 10, 2007.

  1. tshad

    tshad Guest

    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
     
    tshad, Sep 10, 2007
    #1
    1. Advertising

  2. tshad

    Patrice Guest

    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...

    ---
    Patrice

    "tshad" <> a écrit dans le message de news:
    ...
    > 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
    >
     
    Patrice, Sep 10, 2007
    #2
    1. Advertising

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

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


    "tshad" <> wrote in message
    news:...
    > 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
    >
     
    Eliyahu Goldin, Sep 10, 2007
    #3
  4. tshad

    tshad Guest

    "Patrice" <http://www.chez.com/scribe/> wrote in message
    news:%23S%...
    > 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

    >
    > ---
    > Patrice
    >
    > "tshad" <> a écrit dans le message de news:
    > ...
    >> 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
    >>

    >
    >
     
    tshad, Sep 10, 2007
    #4
  5. tshad

    Patrice Guest

    Expected. When you set visible to false server side it is not rendered at
    all in the resulting HTML code (unlike using display:none for example).

    http://msdn2.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerhiddenfield.aspx
    allows to easily render an hidden field (and as said earlier, note that view
    source is enoguh to show its content).

    ---
    Patrice

    "tshad" <> a écrit dans le message de news:
    ...
    > "Patrice" <http://www.chez.com/scribe/> wrote in message
    > news:%23S%...
    >> 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
    >
    >>
    >> ---
    >> Patrice
    >>
    >> "tshad" <> a écrit dans le message de news:
    >> ...
    >>> 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
    >>>

    >>
    >>

    >
    >
     
    Patrice, Sep 10, 2007
    #5
  6. tshad

    tshad Guest

    "Eliyahu Goldin" <> wrote in
    message news:...
    > 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" <> wrote in message
    > news:...
    >> 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
    >>

    >
    >
     
    tshad, Sep 10, 2007
    #6
  7. > 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"
     
    Eliyahu Goldin, Sep 10, 2007
    #7
  8. tshad

    tshad Guest

    "Eliyahu Goldin" <> wrote in
    message news:%...
    >> 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"
    >

    That's what I needed to know.

    Thanks,

    Tom
     
    tshad, Sep 10, 2007
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. 7stud
    Replies:
    11
    Views:
    700
    Dennis Lee Bieber
    Mar 20, 2007
  2. Rick
    Replies:
    3
    Views:
    8,199
    Alexey Smirnov
    Apr 13, 2010
  3. J. Muenchbourg

    asp.net date objects vs. classic asp date objects

    J. Muenchbourg, Oct 3, 2003, in forum: ASP General
    Replies:
    1
    Views:
    174
    msnews.microsoft.com
    Oct 3, 2003
  4. SolarCanine
    Replies:
    2
    Views:
    291
    SolarCanine
    Sep 20, 2005
  5. David

    Hidden Form Objects and asp

    David, Sep 18, 2007, in forum: Javascript
    Replies:
    3
    Views:
    283
    Thomas 'PointedEars' Lahn
    Sep 18, 2007
Loading...

Share This Page