Click here to Skip to main content
15,905,967 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
XML
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
      <script language="javascript" type="text/javascript">
                function chvisible(controlId)
                {
                    var control = document.getElementById(controlId);
                    if(control.style.visibility == "visible" || control.style.visibility == "")
                        control.style.visibility = "hidden";
                    else
                        control.style.visibility = "visible";
                }

</script>

 <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  <input id="Button1" type="button" value="button" onclick="chvisible('TextBox1');"/>


</asp:Content>
Posted
Comments
Sergey Alexandrovich Kryukov 6-Mar-11 13:54pm    
What "does not work"?
--SA

Instead of control.style.visibility, try, control.style.display

For toggling display, use 'block' & 'none' as the two values.

Display property of the style hides the control and yet keeps the control on page to access client side when needed.
 
Share this answer
 
v2
Comments
Hercal 7-Mar-11 4:00am    
thank you for this knowledge
you are right
display is better than visibility
but the main problem was in .............. "chvisible('TextBox1');"
it must be........... "chvisible('<%=TextBox1.ClientID %>');" as Bryain tan said
thank you sandeep mewara
hello,

Also, try use

<input id="Button1" type="button" value="button" onclick="chvisible('<%=TextBox1.ClientID %>');"/>

instead of

<input id="Button1" type="button" value="button" onclick="chvisible('TextBox1');"/>
 
Share this answer
 
v2
Comments
Hercal 7-Mar-11 4:05am    
thank you bryain , you solved my problem :) :)
but why if i make a page.aspx whithout inheritance from master page
and i try to write......onclick="chvisible('TextBox1');" it was done while if i make a page.aspx and inherit from a master page i must write.........onclick="chvisible('<%=TextBox1.ClientID %>');"

you solved my problem but i need to understand
thank you Brian :) :)
Hercal 7-Mar-11 8:10am    
sorry man , if i want to use Check box instead of input button such as

<asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="???????"/>

what will be written instead of Question Marks ??
Bryian Tan 7-Mar-11 10:22am    
hi, I think you can do the same, replace ??? with chvisible('<%=TextBox1.ClientID %>');
Regarding your firs question.
Currently the contents are in a container (ContentPlaceHolder), to avoid naming collision, ASP.NET used an algorithm to determine the client side naming of a server side control. If you look at the HTML source code, the textbox ID will look like ctl00$ContentPlaceHolder1$TextBox1

http://www.msjoe.com/2011/02/asp-net-4-clientid/
Hercal 8-Mar-11 3:42am    
thankx Bryian , but the Expression not success with checkbox which run at server :( :( :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900