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 ?
+3
A:
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!
Chalkey
2009-07-09 10:41:26
That's right but i want that the my form will be design by the userso how many control added dynamically that is not fix.
KuldipMCA
2009-07-09 10:48:58
@KuldipMCA - I think you need to provide so more detail. If you want your users to add dynamic controls at runtime then maybe web parts might be an option?
Andy Rose
2009-07-09 10:53:58
I think what he want is ASP.net 3.5 DynamicControl
Muhammad Akhtar
2009-07-09 10:56:36
1+ is button.ID = "button";
Muhammad Akhtar
2009-07-09 10:59:49
how to get the dyanmic event ??and how we give serverside validation ??
KuldipMCA
2009-07-09 11:02:39
+1
A:
Here is an article that explains how to do it for custom usercontrols.
Sani Huttunen
2009-07-09 10:41:42
+3
A:
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:
How to: Add Controls to an ASP.NET Web Page Programmatically
CraigTP
2009-07-09 10:43:37