-
1
- #1
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
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