473,320 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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="btnAcceptTrips" name="btnAcceptTrips" runat="server"
Text="Accept Trips" Visible="False">

Here's my test method:

function test(checkbox)
{
if (checkbox.checked)
{
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?

Jun 18 '07 #1
5 16280
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="btnAcceptTrips" name="btnAcceptTrips" 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.checked)
{
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.visibility = "visible"
..style.visibility = "hidden"

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 18 '07 #2
Hi Randy,
This works - but to a point. If I start the app off with the button
visible like so:

<asp:button id="btnAcceptTrips" runat="server" Text="Accept Trips"
Visible="True" name="btnAcceptTrips"></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="btnAcceptTrips" runat="server" Text="Accept Trips"
Visible="False" name="btnAcceptTrips"></asp:button>

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

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

Jun 18 '07 #3
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="btnAcceptTrips" runat="server" Text="Accept Trips"
Visible="True" name="btnAcceptTrips"></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="btnAcceptTrips" runat="server" Text="Accept Trips"
Visible="False" name="btnAcceptTrips"></asp:button>

and then start the app, when I try to set the .style.visibility 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">Accept Trips</button>
</form>

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

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Jun 18 '07 #4
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.

Jun 18 '07 #5
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.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 19 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sundown | last post by:
I am trying to create a custom button control for the web that, when clicked, disables and changes the text of itself and a bunch of other controls (in the collection). My goal is to end up with a...
11
by: Dot net work | last post by:
Hello. I've read many posts about disabling submit buttons, but I can't get these answers to solve my problem. I have a server side asp.net button, and under the button I have code behind...
2
by: Red | last post by:
Can you access web form control via javascript ie.. if I have <asp:textbox runat=server id=txtTextbox/> can I say in javascript txtTextbox.Enabled = true; ??
2
by: R Duke | last post by:
I have tried everything I can think of to change the visible property of a design time created control from a dynamically created control's command event handler. Here is the scenario. I have...
3
by: Craig G | last post by:
i have a user control which is basically a datagrid, which has add/edit/delete buttons on the grid is there anyway of accessing the actual datagrid from the form itself? basically i want to...
9
by: Bob | last post by:
Hello: I have a form with 26 panels. Each panel has a bunch of other controls in it. The panels visible property are set to False. Each panel has a corosponding button to set it's visible...
0
by: Keith | last post by:
I have a repeater control that contains a HeaderTemplate and an ItemTemplate. Each item contains a checkbox with an ID of chkReconciled, and the header contains a single checkbox with an ID of...
0
by: Keith | last post by:
I have a repeater control that contains a HeaderTemplate and an ItemTemplate. Each item contains a checkbox with an ID of chkReconciled, and the header contains a single checkbox with an ID of...
8
by: GaryDean | last post by:
I have a Wizard page and need to affect the next and previous buttons from my code-behind. I've googled around and found two solutions, and neither appear to work. I can access the SideBarList...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.