Setting Asp:RadioButtonList visiblity in Javascript

  • Thread starter Thread starter Doogie
  • Start date Start date
D

Doogie

I'm having a problem setting visibility of an asp:RadioButtonList
within javascript.

I want it to be visible when the form is first loaded, so within the
C# code I have the following in the page load function:

gridType.Visible = false;

Simple enough. The problem is that I want the list to show up when a
certain thing is done on the page. Unfortunately, the bulk of that
code exists already and is in javascript. I tried to do the
following, mimicking some of what the other code on the page is doing.

document.all.<%=gridType.ClientID%>.style.visibility = "visible";

But when I do, I get this error:

'document.all.ctl00_MasterContenetPlaceHolder_gridType.style' is null
or not an object.

If I pull the code out of C# and set the grids visibility to false
within the HTML, the javascript code works fine. Setting the
visibility within C# seems to mess up the ability to set it within
Javascript. How do I get around this?
 
If I pull the code out of C# and set the grids visibility to false
within the HTML, the javascript code works fine. Setting the
visibility within C# seems to mess up the ability to set it within
Javascript. How do I get around this?

I ran a quick test and everything works fine. I do not have things as
deeply nested as you do, however.

I noticed that the client name is a bit screwed up in your code:
MasterContenetPlaceHolde. Contenet instead of Content. That probably
means the name is wrong overall, but it is something I would fix,
regardless.

To troubleshoot this error, look at the source and see what the actual
name of the RadioButtonList is. Also, make sure you are making it
invisible with JavaScript, as well, as making things invisible in C# (or
declaratively in the tags) means the code is never output, so the client
side JavaScript can NEVER make it visible. Short story: Use one or the
other, not both.

Peace and Grace,
Greg

--
Vote for Miranda's Christmas Story
http://tinyurl.com/mirandabelieve

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
if you set a server control to Visible=False, then that control will not
be rendered in the browser, so javascript can not access it (as it
doesn't exist). if you want javascript to see it, then set the style
display="none".

also you should not use document.all, as this is an obsolete IE only
method. use:

document.getElementById('<%=gridType.ClientID%>')
.style.visibility = "visible";



-- bruce (sqlwork.com)
 
Back
Top