Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to show or hide controls using checkbox click, client-side?

Status
Not open for further replies.

may1hem

Programmer
Jul 28, 2002
262
GB
I have separate snippets of text which I want joined together to form an email message. My ASP.net page has a radiobuttonlist where the user can select the email circumstance, and based on the selection I want some checkboxes to show or hide. Then, as certain checkboxes are clicked, I want an output box to join together the selected snippets of text into an email message. But I want all of this to happen in the user's browser, i.e. I don't want any posting back to the server. This is because I want this to work on a mobile phone, and not constantly wait for the slow mobile network. At the moment I have it working but it requires a Submit button which causes posting back to the server. How can I do this client side only?
 
You will have to use javascript. I would suggest using JQuery which uses javascript, but it just makes doing javascript coding simpler.

Here is a link to the documentation and an example with just what you need.
 
I agree about the use of Jquery. Sometimes finding the correct ID can be difficult with serverside controls and javascript.
one very usefull snippit for doing so is to refer to the server controls clientId property.
e.g.
<script type='text/javascript'>
$('#<%=txtContent.ClientID%>').hide()
</script>
Would hide the control with an id of txtContent even after asp has renamed it.
The other trick i will use sometime is to asign a css class to a control and use the class to target the control instead as asp.net never messes with classes.

for what it is worth.
 
You can also set the clientIDMode = "Static" on the control and just use the control name. This way if you have a control within a control, it won't matter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top