访问控制编程方式添加回发 [英] Accessing controls added programmatically on postback
本文介绍了访问控制编程方式添加回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在回发:我如何可以访问我的code隐藏文件的ASP.NET控件,它以编程方式添加
On postback: How can I access ASP.NET controls in my code-behind file, which are added programmatically?
我加入一个CheckBox控件到一个占位符控件:
I am adding a CheckBox control to a Placeholder control:
PlaceHolder.Controls.Add(new CheckBox { ID = "findme" });
在ASPX文件中添加的控件都出现在了 Request.Form.AllKeys
罚款除了我添加编程的人。我在做什么错了?
Controls added in the ASPX file are showing up fine in Request.Form.AllKeys
except the ones I add programatically. What am I doing wrong?
启用上的控件使用ViewState中的无助。如果仅仅是这么简单:)
Enabling the use of the ViewState on the controls does not help. If only it was that simple :)
推荐答案
您应该重新创建回发动态控制:
You should recreate your dynamic control on postback:
protected override void OnInit(EventArgs e)
{
string dynamicControlId = "MyControl";
TextBox textBox = new TextBox {ID = dynamicControlId};
placeHolder.Controls.Add(textBox);
}
这篇关于访问控制编程方式添加回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文