Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
.cs

C#
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        StringBuilder str = new StringBuilder();
        str.Append("<script language='javascript'>($('#phnoe').show();)</script>");
        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "chp", str.ToString(), true);
    }


.aspx
ASP.NET
<asp:CheckBox ID="ch_p" Text="phone" runat="server" AutoPostBack="true"
        oncheckedchanged="CheckBox1_CheckedChanged"/>
<div id="p" style="float:left;"><asp:TextBox style="float: left;" runat="server" id="phnoe" Visible="false"></div><br />
Posted
Updated 20-Sep-12 3:56am
v2
Comments
Vani Kulkarni 20-Sep-12 9:57am    
Not working properly means what? What is the issue you are facing?
ashokdamani 20-Sep-12 10:19am    
ultimately its not working as i want
i want tht txtbox will appear/disappear, when chekbox checked/unchecked.....
so what shuld i do ? ? ?
wht will be javascript as well as cs code ?
plz helllllllp
[no name] 20-Sep-12 10:07am    
What about the StringBuilder is not correct? Although, why you are using a StringBuilder for that is anybody's guess.
ashokdamani 20-Sep-12 10:19am    
ultimately its not working as i want
i want tht txtbox will appear/disappear, when chekbox checked/unchecked.....
so what shuld i do ? ? ?
wht will be javascript as well as cs code ?
plz helllllllp

1 solution

If all you are trying to do is show an element on your page when checkbox is ticked\unticked, then you can just do this on the client with a bit of jQuery - no need to have the whole form post back and return script

1) Edit your checkbox control, make sure AutoPostBack is set to false.

2) Add the following script to your page

C#
$(document).ready(function() {

$('#ch_p').click(function() {
    if( $(this).is(':checked')) {
        $('#phnoe').show()
    } else {
        $('#phnoe').hide();
    }
}); 

});



This will show\hide based on whether your checkbox is ticked
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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