How to make controls visible false using javascript...?

Reply

Join Date: Apr 2007
Posts: 26
Reputation: BalagurunathanS is an unknown quantity at this point 
Solved Threads: 0
BalagurunathanS's Avatar
BalagurunathanS BalagurunathanS is offline Offline
Light Poster

How to make controls visible false using javascript...?

 
0
  #1
Aug 16th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: How to make controls visible false using javascript...?

 
0
  #2
Aug 16th, 2007
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:

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ControlVisibilityClientSide.aspx.cs" Inherits="ControlVisibilityClientSide" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" >
  6. <head runat="server">
  7. <title>ControlVisibilityClientSide</title>
  8. <script type="text/javascript">
  9. function toggleVisibility(controlId)
  10. {
  11. var control = document.getElementById(controlId);
  12. if(control.style.visibility == "visible" || control.style.visibility == "")
  13. control.style.visibility = "hidden";
  14. else
  15. control.style.visibility = "visible";
  16.  
  17. }
  18. </script>
  19. </head>
  20. <body>
  21. <form id="form1" runat="server">
  22. <div>
  23. <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  24. <input type="button" ID="btnShowHide" value="Show/Hide" onclick="toggleVisibility('TextBox1');" /></div>
  25. </form>
  26. </body>
  27. </html>
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 26
Reputation: BalagurunathanS is an unknown quantity at this point 
Solved Threads: 0
BalagurunathanS's Avatar
BalagurunathanS BalagurunathanS is offline Offline
Light Poster

Re: How to make controls visible false using javascript...?

 
0
  #3
Aug 16th, 2007
Thanks Holly..I got it..


Regards,
Balagurunathan S
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 2
Reputation: saars is an unknown quantity at this point 
Solved Threads: 0
saars saars is offline Offline
Newbie Poster

Re: How to make controls visible false using javascript...?

 
0
  #4
Dec 1st, 2007
Is it possible to use asp.net button instead of html button?

regrads
saars
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: How to make controls visible false using javascript...?

 
0
  #5
Dec 3rd, 2007
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.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 2
Reputation: saars is an unknown quantity at this point 
Solved Threads: 0
saars saars is offline Offline
Newbie Poster

Re: How to make controls visible false using javascript...?

 
0
  #6
Dec 3rd, 2007
Thanks for replying, but my problem is I have a dropdownlist, when i select 'others' ..... a textbox should appear..since i want to save to the back end.. so i need asp.net button...
thanks in advance.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 53531 | Replies: 5
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC