Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello , i have this code and it run perfectly with input checkbox html contol

<%@ 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.display == "none" || control.style.display == "")
                        control.style.display = "block";
                        control.body.text="";
                    else
                        control.style.display = "none";
                }
</script>
        <asp:TextBox ID="TextBox1" runat="server" Style="display: none"></asp:TextBox>
        <input id="Checkbox1" type="checkbox" onclick="chvisible('<%=TextBox1.ClientID %>');"/>
</asp:Content>




when i change the <input > to CheckBox
what i will write instead of "chvisible('<%=TextBox1.ClientID %>');"
in onCheckedChanged Event ?????

checkbox server side control doesn't have onclick event

when i try to write this following , it don't run

<asp:CheckBox ID="CheckBox2" runat="server" OnCheckedChanged="chvisible('<%=TextBox1.ClientID %>');" />


also it failed if i write

<asp:CheckBox ID="CheckBox1" runat="server" onclick="chvisible('<%=TextBox1.ClientID %>');" Text="sport" />
Posted
Updated 8-Mar-11 1:10am
v2
Comments
@nuraGGupta@ 8-Mar-11 7:11am    
What to you want to do and where is it failing?
Hercal 8-Mar-11 7:33am    
thanx @nura

it done
i wanna to when i check on checkbox , a textbox appear

thankx man

change like this--
<asp:checkbox id="CheckBox2" runat="server" xmlns:asp="#unknown" />


now in form_load in codebehind

CheckBox2.InputAttribute.Add("onchange","chvisible('" +TextBox1.ClientID + "');")


--Pankaj
 
Share this answer
 
Comments
m@dhu 8-Mar-11 7:24am    
Good one.
Hercal 8-Mar-11 7:37am    
thankx pankaj it done but instead of onchange ...... onclick as mkgoud said
but what is the advantage of xmlns:asp="#unknown"
i try code without xmlns:asp="#unknown" and it is success

what about text.body.text=""; it not work :(
i want when a block appeared a text displayed will be null

thank you for your effort
Hercal 8-Mar-11 7:40am    
what if i have 20 textbox and checkbox

Am i use the same way to do that ??

thanx :D :D
checkbox server side control doesn't have onclick event

You can add the onclick event as
CheckBox2.InputAttribute.Add("onclick","chvisible('" +TextBox1.ClientID + "');")
 
Share this answer
 
Comments
Hercal 8-Mar-11 7:38am    
thankx mkgoud , you are right , done
Hercal 8-Mar-11 7:40am    
what if i have 20 textbox and checkbox

Am i use the same way to do that ??

thanx :D :D
m@dhu 8-Mar-11 8:03am    
Though the onclick attribute will not appear in source you can use as
<asp:CheckBox ID="CheckBox1" runat="server" onclick="javascript:alert('test');" />

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