Dinamik Kontrol Oluşturalım
Dinamik bir TextBox kontrolü oluşturalım ve oluşturduğumuz bu kontrole bir TextChange eventi ekleyelim.Asp.Net ile kontrol oluşturmak aynı WinForm ‘da oluşturmaya benzer. Yapı aynıdır ancak bir iki özellik değişir webform’da. Örn: Winform’da AutoPostBack özelliği olmamasına rağmen webform’da böyle bir özellik mevcuttur. Dinamik oluşturulan kontrole göre belirli özellikler değişkenlik gösterebilir. Aşağıdaki kodlar ile ben bir tane TextBox oluşturdum ve TextChange eventine bir olay tanımladım.
[csharp]
protected void Page_Load(object sender, EventArgs e)
{
TextBox txt = new TextBox();
txt.ID = "txtDinamik";
txt.Text = "Ben Dinamik Oluşturuldum.";
txt.AutoPostBack = true;
txt.TextChanged += txt_TextChanged;
this.Form.Controls.Add(txt);
}
void txt_TextChanged(object sender, EventArgs e)
{
Response.Write("Merhaba Dünya");
}
[/csharp]