| | |
How to make controls visible false using javascript...?
![]() |
Hi all..
I am having some controls in my aspx page.I need to write javascript for those controls for validation..For that i need to make the controls visible false in certain situation .I also want to make the controls to visible true in certain sitauations..Some one help me with javascript code for this..
Regards,
Balagurunathan S
I am having some controls in my aspx page.I need to write javascript for those controls for validation..For that i need to make the controls visible false in certain situation .I also want to make the controls to visible true in certain sitauations..Some one help me with javascript code for this..
Regards,
Balagurunathan S
There are many ways to show/hide, render/not render a control
For ASP.NET webcontrols you have the Visible property which can be set to true or false but that's serverside.
For client side you have visibility attribute in CSS which can be "visible" or "hidden", here is an example:
For ASP.NET webcontrols you have the Visible property which can be set to true or false but that's serverside.
For client side you have visibility attribute in CSS which can be "visible" or "hidden", here is an example:
asp Syntax (Toggle Plain Text)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ControlVisibilityClientSide.aspx.cs" Inherits="ControlVisibilityClientSide" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>ControlVisibilityClientSide</title> <script type="text/javascript"> function toggleVisibility(controlId) { var control = document.getElementById(controlId); if(control.style.visibility == "visible" || control.style.visibility == "") control.style.visibility = "hidden"; else control.style.visibility = "visible"; } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <input type="button" ID="btnShowHide" value="Show/Hide" onclick="toggleVisibility('TextBox1');" /></div> </form> </body> </html>
Yes it is, an asp:Button will cause a postback and you can make controls visible property true/false server side. The OP asked for javascript to show/hide controls on the page client-side. The only reason to show/hide controls with javascript is because a postback serverside is a lot of network and server resources re-constructing a whole page just to hide/show one or two controls. So, as we were discussing client-side code an asp:Button was not necessary.
![]() |
Similar Threads
- Make a VB Program run in the background? (VB.NET)
- to make checkboxes visible in datagrid C# windows application (C#)
- checkbox in datagrid (ASP.NET)
- Getting values from GridView Controls (ASP.NET)
- Problems with Directory.Move (C#)
- owner form display problem (VB.NET)
- Timing frames on a form (Visual Basic 4 / 5 / 6)
- Control array (Visual Basic 4 / 5 / 6)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Firefox, javascript and document object
- Next Thread: returning array from ajax.responseText?
Views: 53531 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ajax ajaxexample ajaxjspservlets alert array auto blackjack box browser bug calling captchaformproblem checkbox child class close content css dependent dialog disablefirebug div dom editor element engine events explorer ext file flash form forms function game gears google gxt hiddenvalue highlightedword html ie8 iframe internet java javascript javascripthelp2020 jquery jsf jsfile jsp jump libcurl load maps margin math matrixcaptcha media mysql object objects onerror onmouseoutdivproblem onreadystatechange parent passing paypal pdf php player post rated refresh resize runtime script scroll search security select session shopping size software solutions star stars stretch synchronous table unicode values variables video web window wysiwyg xhtml \n






