<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" Title="Untitled Page" %>
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";
}
when i change the to CheckBox
what i will write instead of "chvisible('<%=TextBox1.ClientID %>');"
in onCheckedChanged Event ?????
checkbox serverside control doesnt hava onclick event
when i try to write this following , it dont run
Raja KrishnamurthyRank #3,615 · 403 reputationPosted Mar 8, 2011, 2:31 AM EST
Please try this:
On pageload
Checkbox1.Attributes.Add("onclick","chvisible('"+TextBox1.ClientID+"');");
The error you are getting is because the ClientID might not have rendered. And you can remove the onCheckedChanged which you have given in the Checkbox tag. Also don't forget to check for postback.
HTH
Happy Programming!!!
Regards,
Raja
Manikavelu VelayuthamRank #413 · 6K reputationPosted Mar 8, 2011, 1:46 AM EST
You can use the same OnClick event like in Html control for client side event.
Bassem20 reputationPosted Mar 8, 2011, 1:55 AM EST
but it also not success when i write
Manikavelu VelayuthamRank #413 · 6K reputationPosted Mar 8, 2011, 2:11 AM EST
2. if(control.style.display == "none" || control.style.display == "")
{
Include the content of true condition with braces.
3. OnCheckedChanged="chvisible('TextBox1.ClientID');"
Put it like above .
If the above changes done, your code will work fine
Bassem20 reputationPosted Mar 8, 2011, 2:23 AM EST
error in the line of checkbox :
Manikavelu VelayuthamRank #413 · 6K reputationPosted Mar 8, 2011, 2:30 AM EST
Bassem20 reputationPosted Mar 8, 2011, 2:47 AM EST
try it with yourself it will not work
thank your for helping me :)
when i use
Checkbox1.Attributes.Add("onclick","chvisible('"+TextBox1.ClientID+"');");
it work perfectly
about text displayed in text box
and about this crazy line which make you angry control.body.text=""; :D :D (^_^)
how i make textbox null when user check on it (javascript code)
thanx Manikavelu , u are good helper
Raja KrishnamurthyRank #3,615 · 403 reputationPosted Mar 8, 2011, 2:50 AM EST
I think you mean to make the text in the textbox as "" and not making the textbox as null.
Add this to your JS
control.value="";
HTH.
Happy Programming!!!
Regards,
Raja
Bassem20 reputationPosted Mar 8, 2011, 2:54 AM EST
it works correctly :D :D Thank you .
what if i have 20 textbox and checkbox Am i use the same way to do that ??
what about this question :) ?
how i make textbox null when user check on it (javascript code)
thank you man :)
Bassem20 reputationPosted Mar 8, 2011, 2:58 AM EST
i do as u said
but unfortunately not work .
Raja KrishnamurthyRank #3,615 · 403 reputationPosted Mar 8, 2011, 2:59 AM EST
What do you mean by How do I make textbox as null?
Do you want to remove from the DOM? I think your code of making it visible / invisible and setting the text as "" is fine.
HTH.
Happy Programming!!!
Regards,
Raja
Raja KrishnamurthyRank #3,615 · 403 reputationPosted Mar 8, 2011, 3:06 AM EST
HTH.
Happy Programming!!!
Regards,
Raja
Bassem20 reputationPosted Mar 8, 2011, 3:07 AM EST
Bassem20 reputationPosted Mar 8, 2011, 3:13 AM EST
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts