Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding User Controls Programmatically 1

Status
Not open for further replies.

link9

Programmer
Nov 28, 2000
3,387
US
Hello all --

Next stumbling block in ASP.NET:
Adding user controls programmatically to a web form.

You can check out this article from MS for the basics:

BUT! What they neglect to tell you here is that if your user control has any form functionality whatsoever (ie. post back), then it will return an error if you simply add the user control to the page's control collection. The error returned is that whatever button in question has to be w/in a form tag... how nice.

Well, luckily for us, labels have a control collection, too (since they inherit from page), and if you place a label between the form tag on the web form page, then all you do is:

lblName.Controls.Add(userControl)

instead of

page.Controls.Add(userControl)

Hope this saves someone some time! :)
paul
penny1.gif
penny1.gif
 
thanks bro!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top