472,342 Members | 1,300 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 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 14441
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...
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...
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...
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...
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...
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:...
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...
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...
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....
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

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.