Any body have idea how to put controls dynamically in asp.net 3.5 ? if any example please provide to me. another Question : is it possible to create Event for Dynamic Controls ?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Here is an example (including creating an event) for ASP.NET dynamic controls...
protected void Page_Load(object sender, EventArgs e)
{
Button button = new Button();
button.Text = "Click me";
button.Click += new EventHandler(ButtonClick);
this.Form.Controls.Add(button);
}
private void ButtonClick(object sender, EventArgs e)
{
(sender as Button).Text = "You just clicked me!";
}
Hope it helps!
回答2:
It is certainly possible, and it's possible to "wire up" a controls events despite it being created dynamically.
See the following links for full information:
Dynamic Controls in ASP.NET
How to: Add Controls to an ASP.NET Web Page Programmatically
Dynamic ASP.Net Control Creation Using C#.Net
How To Dynamically Add Controls to a Web Page Video
回答3:
Here is an article that explains how to do it for custom usercontrols.