473,466 Members | 1,381 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How do I show/hide Label/Textbox when a RadioButton is clicked?

I am new to WebForms and am far more comfortable with WinForms. I am
wondering how simple things such as showing/hiding a label and textbox can
be accomplished if a certain Radiobutton option is clicked/unclicked without
taking a trip back to the webserver? Is there some easy way to do this? (I'm
gussing it will require JavaScript)
Nov 18 '05 #1
3 14965
Javascript is the route to take.

I would wire to the "onclick" event of the radio button.

The javascript I use to show and hide controls is:

document.all["tblShowMe"].style.display = "";
document.all["tblHideMe"].style.display = "none";

If you need more info, let me know.

HTH,

bill
tblReplacementInvoice.style.display = "none"
"Jason" <nf*@nospam.com> wrote in message
news:eX**************@TK2MSFTNGP11.phx.gbl...
I am new to WebForms and am far more comfortable with WinForms. I am
wondering how simple things such as showing/hiding a label and textbox can
be accomplished if a certain Radiobutton option is clicked/unclicked without taking a trip back to the webserver? Is there some easy way to do this? (I'm gussing it will require JavaScript)

Nov 18 '05 #2
Without going back to the server it does require javascript, something
untested like:
<asp:label id="usernameLabel" runat="server" /> <asp:dropdownlist id="ddl"
runat="server" onChange="changed(this);" />
<script language="javascript">
function changed(ddl){
var username = document.getElementById('<%=usernameLabel.UniqueId %>');
switch (ddl.options[ddl.selectedIndex].value){
case "1":
username.style.visibility = 'hidden';
break;
default:
username.style.visibility = 'visible';
break;
}
}

</script>

That's just a basic example,
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Jason" <nf*@nospam.com> wrote in message
news:eX**************@TK2MSFTNGP11.phx.gbl...
I am new to WebForms and am far more comfortable with WinForms. I am
wondering how simple things such as showing/hiding a label and textbox can
be accomplished if a certain Radiobutton option is clicked/unclicked without taking a trip back to the webserver? Is there some easy way to do this? (I'm gussing it will require JavaScript)

Nov 18 '05 #3
I also discovered that if I use the RadioButtonList, set
AutoPostBack="True", and hook the SelectedIndexChanged event I can
hide/unhide labels and textboxes using C# rather than JavaScript.

However, it is obvious it would be much more efficient to use JavaScript for
something like this... so I guess I better learn it.

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:ue**************@tk2msftngp13.phx.gbl...
Without going back to the server it does require javascript, something
untested like:
<asp:label id="usernameLabel" runat="server" /> <asp:dropdownlist id="ddl"
runat="server" onChange="changed(this);" />
<script language="javascript">
function changed(ddl){
var username = document.getElementById('<%=usernameLabel.UniqueId %>');
switch (ddl.options[ddl.selectedIndex].value){
case "1":
username.style.visibility = 'hidden';
break;
default:
username.style.visibility = 'visible';
break;
}
}

</script>

That's just a basic example,
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/

Nov 18 '05 #4

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

Similar topics

0
by: Efkas | last post by:
I have a full custom application with some widged extending Controls like Label and PictureBox. I build a menu with these widgets. When I click on one of them, it calls a function to display...
1
by: Josema | last post by:
Hi to all, I have a textbox and a button... When the button its clicked i show a label that has the text "Hello World"... I would like to make that, when the button its clicked, first show an...
1
by: sarj | last post by:
Hi.... I have a asp:textbox whose text needs to be set when a radio button is clicked. The text would correspond to the value of the particular. However, although the text is correctly set in...
4
by: Mark Broadbent | last post by:
This one has got me absolutely stumped. At work I have created a simple web form that gets data from a sql backend and puts this to a dataset. I have an edit button that when clicked will set...
4
by: bridgemanusa | last post by:
Hi All: I have a very long page of html that I want to take portions and hide them in divs, then show when a link is clicked. I have the hide show part working when the link is clicked, however...
2
by: UJ | last post by:
Is there a way with a asp:checkbox to run a JavaScript to display/hide text/input on the screen without doing a postback? I also need to be able to access the stuff at the server so I need to...
1
by: rn5a | last post by:
A ASPX page has a RadioButtonList with 2 ListItems - 'Yes' & 'No' <form runat="server"> <asp:RadioButtonList ID="rdlAdd" OnSelectedIndexChanged="ShowHide" AutoPostBack="true" runat="server">...
3
by: timplx | last post by:
Hello all, New to javascript and have never worked with programming languages like c++, so my logic in some of these statements might be incorrect or redundant Got a problem with my page......
11
Ciary
by: Ciary | last post by:
hey all, i have a problem with radio buttons showing and hiding divs in IE. i can't figure out what the problem is. when i click on the radiobutton nothing changes. it's only when i click...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.