单击按钮后获取运行时生成的复选框值 [英] Get runtime genrated checkbox value after clicking on a button
问题描述
protected void btnSet_Click(对象发件人,EventArgs e)
{
CheckBox chkBx = new CheckBox();
chkBx.ID = chk1;
appentDiv.Controls.Add(chkBx);
}
受保护 void btnGet_Click( object sender,EventArgs e)
{
CheckBox n = this .appentDiv.FindControl( chk1) as CheckBox;
}
可以帮忙从这里获取复选框值...?
请回复...
问候
Sujeet Singh
它为我工作
protected void btnGet_Click(对象发件人,EventArgs e)
{
CheckBox n =(CheckBox) this .appentDiv.FindControl( chk1);
}
你将获得null $
this .appentDiv.FindControl( chk1) as CheckBox
原因是回发后动态添加的控件将无法使用。 ..
所以你需要使用Session或Viewstate处理这个...
请检查这些链接...
解决PostBack动态控制问题 [ ^ ]
http://chiragrdarji.wordpress.com/2009/05/20/maintain-v iewstate-for-dynamic-controls-across-the -backback / [ ^ ]
http://www.codestructs.com/tag-blogger-com-1999-blog-2555797619867133640-post-2780447821170012635 [ ^
protected void btnSet_Click(object sender, EventArgs e)
{
CheckBox chkBx = new CheckBox();
chkBx.ID = "chk1";
appentDiv.Controls.Add(chkBx);
}
protected void btnGet_Click(object sender, EventArgs e)
{
CheckBox n = this.appentDiv.FindControl("chk1") as CheckBox;
}
Could any please help to get checkbox value from here...?
Please reply...
Regards
Sujeet Singh
Its working for me
protected void btnGet_Click(object sender, EventArgs e) { CheckBox n = (CheckBox)this.appentDiv.FindControl("chk1") ; }
You will be getting null at
this.appentDiv.FindControl("chk1") as CheckBox
The reason is Dynamically added controls will not be available after postback....
So you need to handle this by using Session or Viewstate...
Please check these links...
Solve Dynamic Control Problem With PostBack[^]
http://chiragrdarji.wordpress.com/2009/05/20/maintain-viewstate-for-dynamic-controls-across-the-postback/[^]
http://www.codestructs.com/tag-blogger-com-1999-blog-2555797619867133640-post-2780447821170012635[^]
这篇关于单击按钮后获取运行时生成的复选框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!