Accessing invisible control in Javascript

Discussion in 'Javascript' started by ipramod@gmail.com, Sep 25, 2007.

  1. Guest

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

  2. Henry Guest

    On Sep 25, 6:04 pm, Randy Webb wrote:
    > said the following on 9/25/2007 10:25 AM:

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

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

    <snip>
    >> 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"

    >
    > 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.
     
    Henry, Sep 25, 2007
    #2
    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. Dag Sunde
    Replies:
    8
    Views:
    3,128
    Andrew T.
    May 10, 2006
  2. Charlie@CBFC
    Replies:
    6
    Views:
    94,060
    Laurent Bugnion
    May 15, 2006
  3. Replies:
    3
    Views:
    4,238
    Mark Rae [MVP]
    Sep 25, 2007
  4. Andy B
    Replies:
    5
    Views:
    627
    Andy B
    May 29, 2008
  5. TS
    Replies:
    5
    Views:
    885
Loading...

Share This Page