如何动态检查(Radiobutton1.Checked == True)的值? [英] How Do I Checked The Value Of (Radiobutton1.Checked == True) Dynamically ?
本文介绍了如何动态检查(Radiobutton1.Checked == True)的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
//global object for radiobutton1 is created for access all over to form
static RadioButton RadioButton1 = new RadioButton();
//here i am assinging in particular div which id is "RadioDiv1"
Control myControl1 = FindControl("RadioDiv1");
myControl1.Controls.Add(RadioButton1);
RadioButton1.Enabled = true;
RadioButton1.EnableViewState = true;
RadioButton1.AutoPostBack = false;
RadioButton1.ID = "RadioButton1";
myControl1.Controls.Add(new LiteralControl(""));
RadioButton1.CheckedChanged += new EventHandler(RadioButton1_CheckedChanged);
//this is the checkedChanged event
private void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
if (!RadioButton1.Checked)
{
RadioButton1.Checked = true;
}
else
{
RadioButton1.Checked = false;
}
}
//But after clicking on the radiobutton1 the checked changed event is not fired, I am checking the value of Radiobutton1.checked == true
// even after select it gives me false .
string user_ans = "";
if (RadioButton1.Checked == true)
{
user_ans += "A";
}
注意: - 这里radiobutton是在页面加载时创建的对象,但我分配了它的属性动态,并在开始时我没有分配其检查值。我无法理解发生了什么,请帮我解决这个问题
推荐答案
点击此链接
http://stackoverflow.com / questions / 4365500 / dynamic-generated-radio-button-calling-checkedchanged-event [ ^ ]
你可以在 autopostback = true中尝试一个函数
if(!ispostbck)
{
RadioButton1_CheckedChanged(this,null);
}
if(!ispostbck)
{
RadioButton1_CheckedChanged(this,null);
}
可能是他lp you ..
it may help you..
RadioButton1.AutoPostBack = false;
如果要调用服务器端checkedchange事件,则需要将AutoPostBack标志设置为true
"RadioButton1.AutoPostBack = false;"
if you want to call server side checkedchange event you need to set AutoPostBack flag to true
这篇关于如何动态检查(Radiobutton1.Checked == True)的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文