Tuesday, December 8, 2009

Accessing controls created dynamically in asp.net using c#.net or VB.net



Accessing controls created dynamically in asp.net using c#.net or VB.net


An important asp.net programmers should know is how to create controls dynamically and after creating how to access them. Here we are describing these two things shorly.

Creating Controls dynamically

Here we are descibing how to create a textbox and added to a div

div should be




TextBox txt= new TextBox();
txt.id="Txt1";
div1.Controls.Add(txt);

How To Findcontrol

See the below example how to find the added textbox and setting text to it

TextBox txt=((TextBox)div1.FindControl("Txt1");
txt.Text="Found U";

If You want to add attributes

txt.Attributes.Add("onFocus()","alert(this)");


REGARDS
Jeevan

No comments:

Post a Comment