单击复选框后使文本框可见 [英] make a textbox visible after clicking checkbox

查看:214
本文介绍了单击复选框后使文本框可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在选中复选框后,如何使文本框可见?

您如何改进下面的代码?

How could you make a text box visible after checking a checkbox?

How do you improve the code below?

if(checkbox1.Checked)
{
textbox1.Visible = true;
}
else
{
textbox1.Visible= false;
}


推荐答案

Hello,

添加到以前的答案...

您可以使它更短::)

Hello,

Adding to the previous answers...

You could make it even shorter: :)

protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
    TextBox1.Visible = CheckBox1.Checked;
}




Valery.




Valery.


选中您的复选框,单击事件",然后双击:

CheckStateChanged

这将创建事件处理程序.在其中输入您的代码.它看起来应该像:

Select your checkbox, click Events and double-click on the:

CheckStateChanged

This will create the event handler. Enter your code inside it. It should look like:

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


将复选框的AutoPostback 设置为true.
然后在OnCheckedChanged
Set AutoPostback of checkbox true.
And write your code in OnCheckedChanged


这篇关于单击复选框后使文本框可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆