The Stock Directory is a directory of Photography Websites, Stockphoto Website, Photography Blogs, Forums, Photosharing and Printing Website
Monday, December 14, 2009
Saturday, October 31, 2009
Adding Server Control Dynamically in ASP.Net
New or Casual Coder feels difficult to create asp.net server controls dynamically. I am givin an example to add Panel Control(which servers as a containter for other server controls ) and a Label control into asp.net form dynamically. The following in the code portion which is to be written in the Page_Load.
protected void Page_Load(object sender, EventArgs e)
{
Panel p1 = new Panel();
this.form1.Controls.Add(p1);
Label l1= new Label();
l1.Text="Test Label in Panel";
p1.Width = 200;
p1.Height = 200;
p1.BackColor = System.Drawing.Color.Red;
p1.BorderColor = System.Drawing.Color.Black;
p1.Controls.Add(l1);
p1.Visible = true;
p1.Enabled = true;
}
Explanation:
First line on code creates an instance of Panel by the name p1, second line adds this panel instance "p1" to the current asp.net form "form1", next line creates an instance of lable control in the name of "l1" and assign some text to it. Next line changes some properties like height, width and backgournd color etc. After that Newly created label "l1" is added to a panel "p1";
Posted by
Shariq Khan
at
6:19 AM
0
comments
Monday, September 8, 2008
Indian Coins and Numsimatics Forum
Posted by
Shariq Khan
at
9:37 PM
0
comments
