Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hello Guys,

I need text box should be visible when checkbox is checked.

I created the code but it's not working,

Error:- Expected end of statement, Line No:1

C#
private void checkBox1_CheckStateChanged(object sender, EventArgs e)
{
   if(checkbox1.Checked)
   {
      textbox2.Visible = true;
   }
   else
   {
      textbox2.Visible= false;
   }
}


Thanks In advance
Posted
Updated 26-Apr-12 23:08pm
v3
Comments
VJ Reddy 27-Apr-12 4:38am    
Edit: pre tag for C# code added.
Zuby2012 27-Apr-12 5:43am    
What do you mean?
Sergey Alexandrovich Kryukov 27-Apr-12 15:53pm    
He means HTML tags <pre> Use "Improve question" and see its HTML source code to see how it should be done.
--SA
Sandeep Mewara 27-Apr-12 5:05am    
What do you mean by 'it's not working'?
This is not a well framed question! We cannot work out what you are trying to do/ask from the post. Please elaborate and be specific.
Use the "Improve question" link to edit your question and provide better information.
Zuby2012 27-Apr-12 5:43am    
I just changed the question

1 solution

The problem is different: you complain about some code, but provide a code sample for some other, which does not have a problem. All you need at this moment is a bit more attention and accuracy. All figure brackets '{', '}' inside the body of the function are redundant, but this is not a mistake at all (and some just use such style).

Also, I always recommend anonymous methods for event handler. And naming is quite bad, violates Microsoft naming conventions. Again, there is no a bug there.

—SA
 
Share this answer
 
Comments
Zuby2012 30-Apr-12 4:35am    
Hello Mate,
Which Event handler should i choose to run this script?
Sergey Alexandrovich Kryukov 30-Apr-12 18:45pm    
First, what script? C# is not a scripting language.
Your code should work; but what event to use depends on what you want to achieve...
--SA
Zuby2012 1-May-12 4:06am    
I am using script editor in Outlook form,
I want to achieve , when user checked checkbox, textbox should be visible.
Sergey Alexandrovich Kryukov 7-May-12 20:06pm    
Why writing what you have written? It's just
textbox2.Visible = checkbox1.Checked;
--SA

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