Accessing ASP Button visible property in JavaScript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Doogie

    Accessing ASP Button visible property in JavaScript

    Hi,
    I am trying to access the visible property of an ASP button inside
    javascript to no avail. Here's what my button control looks like:

    <asp:Button id="btnAcceptTr ips" name="btnAccept Trips" runat="server"
    Text="Accept Trips" Visible="False" >

    Here's my test method:

    function test(checkbox)
    {
    if (checkbox.check ed)
    {
    document.Form1. btnAcceptTrips. visible = true
    }
    }

    I get an error saying this object is null or doesn't exist. So I
    played around with this. I can verify that I can access the
    btnAcceptTrips object within javascript, I can even access the
    btnAcceptTrips object name property value, but visible doesn't appear
    to be accessible. I've tried "Visible" and "visible".

    Does anyone know how to get access to this value?

  • Randy Webb

    #2
    Re: Accessing ASP Button visible property in JavaScript

    Doogie said the following on 6/18/2007 11:08 AM:
    Hi,
    I am trying to access the visible property of an ASP button inside
    javascript to no avail. Here's what my button control looks like:
    >
    <asp:Button id="btnAcceptTr ips" name="btnAccept Trips" runat="server"
    Text="Accept Trips" Visible="False" >
    What your server code looks like is irrelevant. What is important is the
    HTML that the browser gets.
    Here's my test method:
    >
    function test(checkbox)
    {
    if (checkbox.check ed)
    {
    document.Form1. btnAcceptTrips. visible = true
    }
    }
    >
    I get an error saying this object is null or doesn't exist. So I
    played around with this. I can verify that I can access the
    btnAcceptTrips object within javascript, I can even access the
    btnAcceptTrips object name property value, but visible doesn't appear
    to be accessible. I've tried "Visible" and "visible".
    >
    Does anyone know how to get access to this value?
    Visibility is a property of the style object.

    ..style.visibil ity = "visible"
    ..style.visibil ity = "hidden"

    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

    Comment

    • Doogie

      #3
      Re: Accessing ASP Button visible property in JavaScript

      Hi Randy,
      This works - but to a point. If I start the app off with the button
      visible like so:

      <asp:button id="btnAcceptTr ips" runat="server" Text="Accept Trips"
      Visible="True" name="btnAccept Trips"></asp:button>

      then everything works fine.

      But if I set the visibility property of the control to false like this
      (and this will be the way my app neds to be have:

      <asp:button id="btnAcceptTr ips" runat="server" Text="Accept Trips"
      Visible="False" name="btnAccept Trips"></asp:button>

      and then start the app, when I try to set the .style.visibili ty value
      I get this error:

      'document.Form1 .btnAcceptTrips .style' is null or not an object.

      Comment

      • -Lost

        #4
        Re: Accessing ASP Button visible property in JavaScript

        Doogie wrote:
        Hi Randy,
        This works - but to a point. If I start the app off with the button
        visible like so:
        >
        <asp:button id="btnAcceptTr ips" runat="server" Text="Accept Trips"
        Visible="True" name="btnAccept Trips"></asp:button>
        >
        then everything works fine.
        >
        But if I set the visibility property of the control to false like this
        (and this will be the way my app neds to be have:
        >
        <asp:button id="btnAcceptTr ips" runat="server" Text="Accept Trips"
        Visible="False" name="btnAccept Trips"></asp:button>
        >
        and then start the app, when I try to set the .style.visibili ty value
        I get this error:
        >
        'document.Form1 .btnAcceptTrips .style' is null or not an object.
        Quote what you respond to so everyone can follow along without having to
        reference threads that may not be available.

        Also, just like Mr. Webb said, you need to worry about (valid) HTML.
        Without it, JavaScript cannot behave consistently.

        Start with this and or modify until you get what you want.

        <form id="form1">
        <button name="button1" type="button">A ccept Trips</button>
        </form>

        <script>
        document.forms['form1'].elements['button1'].style.visibili ty = 'hidden';
        </script>

        --
        -Lost
        Remove the extra words to reply by e-mail. Don't e-mail me. I am
        kidding. No I am not.

        Comment

        • Doogie

          #5
          Re: Accessing ASP Button visible property in JavaScript

          Quote what you respond to so everyone can follow along without having to reference threads
          that may not be available.
          Why would a reference thread not be available (just curious).
          Personally, I find the additional quotes annoying to parse through.
          Also, just like Mr. Webb said, you need to worry about (valid) HTML. Without it, JavaScript cannot behave consistently.
          What is invalid about my html? I created it directly from within .NET
          by dumping the control onto my form and setting the visible property
          to false (which is what I need). I need this control to be invisible
          when the app starts, and then my javascript method will make it
          visible or invisible depending on condtions. If I start with the
          control visible and run through setting it's visibility in javascript
          it works, but if I start with it invisible it does not work.



          Comment

          • Randy Webb

            #6
            Re: Accessing ASP Button visible property in JavaScript

            Doogie said the following on 6/18/2007 4:12 PM:
            >Quote what you respond to so everyone can follow along without having to reference threads
            >that may not be available.
            >
            Why would a reference thread not be available (just curious).
            Personally, I find the additional quotes annoying to parse through.
            Because, in my case, I have already read the message you are replying to
            (in fact, I wrote it). And since I have already read it, and not marked
            it unread, Thunderbird doesn't show it to me anymore unless I go through
            certain steps to view it again. Quoting what you are replying to
            prevents that from ever happening.
            >Also, just like Mr. Webb said, you need to worry about (valid) HTML.
            >Without it, JavaScript cannot behave consistently.
            What is invalid about my html?
            Good question :) Since you posted the server side code (which I said was
            irrelevant) nobody would know what the browser got without having an
            ASP.NET server to serve it to the browser to see. When posting code
            here, post the resulting HTML and not the server code that generates it.
            I created it directly from within .NET
            I am not a big fan of the HTML that .NET produces.
            by dumping the control onto my form and setting the visible property
            to false (which is what I need). I need this control to be invisible
            when the app starts, and then my javascript method will make it
            visible or invisible depending on condtions. If I start with the
            control visible and run through setting it's visibility in javascript
            it works, but if I start with it invisible it does not work.
            Then start with it visible and immediately hide it.

            --
            Randy
            Chance Favors The Prepared Mind
            comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
            Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

            Comment

            Working...