942,956 Members | Top Members by Rank

Ad:
Aug 16th, 2007
0

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

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
BalagurunathanS is offline Offline
26 posts
since Apr 2007
Aug 16th, 2007
0

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

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:

asp Syntax (Toggle Plain Text)
  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>
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005
Aug 16th, 2007
0

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

Thanks Holly..I got it..


Regards,
Balagurunathan S
Reputation Points: 10
Solved Threads: 0
Light Poster
BalagurunathanS is offline Offline
26 posts
since Apr 2007
Dec 1st, 2007
0

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

Is it possible to use asp.net button instead of html button?

regrads
saars
Reputation Points: 10
Solved Threads: 0
Newbie Poster
saars is offline Offline
2 posts
since Dec 2007
Dec 3rd, 2007
0

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

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.
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005
Dec 3rd, 2007
0

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

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
saars is offline Offline
2 posts
since Dec 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Firefox, javascript and document object
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: HELP needed on javascript menus PLEASE...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC