如何实现代码 [英] How to implement the code
本文介绍了如何实现代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写代码,以便选择单选按钮将禁用文本框.文本框的默认状态应为启用.任何想法我应该如何编码?
I am trying to write code so that selecting a radio button will disable a textbox. The default state of the textbox should be enable. Any ideas how I should code this?
推荐答案
您还可以缩短已经提供给此行的代码:
You could also shorten the code already presented to this single line:
TextBox1.Enabled = (!RadioButton1.Checked);
在Page_Load
事件上,编写以下代码.
OnPage_Load
event , write the following code.
protected void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack) {
TextBox1.Enabled = true;
}
}
在RadioButton1_CheckedChanged
事件上,编写以下代码.
On RadioButton1_CheckedChanged
event, write the following code.
protected void RadioButton1_CheckedChanged(object sender, System.EventArgs e)
{
if (RadioButton1.Checked) {
TextBox1.Enabled = false;
} else {
TextBox1.Enabled = true;
}
}
在表单加载时:
Textbox1.Enabled = False;
on Form Load:
Textbox1.Enabled=False;
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (Textbox1.Enabled==False)
{Textbox1.Enabled=True;
}
else
{Textbox1.Enabled=False;}
}
这篇关于如何实现代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文