控制添加回发问题 [英] Control Add PostBack Problem
本文介绍了控制添加回发问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我动态添加控件,但是; easc回发事件我的控件不见了.我看不到我的控件.
I Add Control Dynamiclly but; easc Postback event my controls are gone. I Can not see again my controls.
那么我该如何添加控件?
So How can I add control ?
推荐答案
在Page的Init事件中添加控件,这些控件在回发时将保留在viewstate中.确保它们具有唯一的ID.
Add the controls in the Page's Init event and they will be preserved in viewstate when posting back. Make sure they have a unique ID.
查看此链接...
一个非常简单的例子.
public partial class MyPage : Page
{
TextBox tb;
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
tb = new TextBox();
tb.ID = "testtb";
Page.Form.Controls.Add(tb);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
//tb.Text will have whatever text the user entered upon postback
}
}
这篇关于控制添加回发问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文