473,395 Members | 1,931 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,395 software developers and data experts.

asp:checkbox hide/show text/fields when it's clicked without doing a postback?

UJ
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 have
run=server with it.

TIA - Jeff.
Apr 26 '06 #1
2 14601
Yes you can add javascript to the control.

in your code behind you can do this through ...

Checkbox.Attributes.Add("onclick", "yourjavascriptfunction(this)")

"UJ" <fr**@nowhere.com> wrote in message
news:uC*************@TK2MSFTNGP05.phx.gbl...
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 have
run=server with it.

TIA - Jeff.

Apr 26 '06 #2
Yes there are ways to do that. the asp:checkbox ultimately renders a an
<input type='checkbox'> html tag to the web browser .
if it were a html control you can do this by adding an onclick attibute to
the tag i.e. <input type='checkbox' onclick='someJavaScript();'> right?
you can also do that with an asp:CheckBox control by adding the attribute
key, value pair to the Attributes collection of the control thus:
CheckBox.Attributes.Add("attributename","attribute value") .

copy, save and host the code below. The trick is in the OnInit method where
the onClick attribute of the checkbox is added.

<%@ Page language="c#" AutoEventWireup="false" %>
<HTML>
<HEAD>
<title>Javascript Show Hide</title>

<script language=javascript>
function showHide(checkbox,textboxId)
{
var textbox = document.getElementById(textboxId);
if(checkbox.checked)
{
textbox.style.display = '';
}
else
{
textbox.style.display = 'none';
}
}
</script>
<script language=C# runat=server>
override protected void OnInit(EventArgs e)
{
chbShowHide.Attributes.Add("onClick",string.Format ("javascript:showHide(this,'{0}');",txtShowHide.Cl ientID));
base.OnInit(e);
}
</script>
</HEAD>
<body >
<form id="frmShowHide" method="post" runat="server">
<asp:TextBox id="txtShowHide"
runat="server"></asp:TextBox>
<asp:CheckBox id="chbShowHide" Checked=True
runat="server"></asp:CheckBox>
</form>
</body>
</HTML>

"UJ" <fr**@nowhere.com> wrote in message
news:uC*************@TK2MSFTNGP05.phx.gbl...
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 have
run=server with it.

TIA - Jeff.

Apr 26 '06 #3

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

Similar topics

19
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
17
by: wolfing1 | last post by:
Like, I know if several checkboxes have the same name, I can get the ones that were checked after submit with a request.form("name") and maybe do a split(request.form("name"),",") to cycle through...
0
by: Maziar Aflatoun | last post by:
Hi everyone, I am reading and displaying data rows from my database where the first column contains the Status checkbox. I like to enable my users to change the status of individual rows by...
2
by: Maziar Aflatoun | last post by:
Hi everyone, I am reading and displaying data rows from my database where the first column contains the Status checkbox. I like to enable my users to change the status of individual rows by...
1
by: Norman | last post by:
Hello All, I have developed the ASP.Net application using .Net 1.1. I want to get one section of the page under hide/show feauture. That means when the user clicks on display I want to display all...
3
by: Jim Bancroft | last post by:
Hi everyone, This is a silly one I'm sure, but I'm having a whale of a time putting some text into my asp checkbox. Here's what I'd like to do: <asp:CheckBox runat="server"...
10
by: mwieder | last post by:
I've got an ASP.NET form with a textbox and a customvalidator. The form inherits from a base wizard class with back, next and cancel buttons. The CausesValidation property of the Cancel button...
4
by: =?Utf-8?B?U3JpZGhhcg==?= | last post by:
Hi, Is it possible to Hide/Show controls during a callback? I have a radio button list that does the callback. When it does the callback I need to refresh the grid to reflect the selected value...
1
by: yimma216 | last post by:
Beginner javascipt/vbscript. I hava a form, which has five lines to enter at start. I want to have a button to add more lines when it is clicked. However, I am having trouble with it. This is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.