Optimal way to create webcontrols?

  • Thread starter Thread starter Krister Kauppi
  • Start date Start date
K

Krister Kauppi

What is the optimal way to create a webcontrol? Is it in the aspx-page
or in the code-behind (A or B)?

A. <asp:TextBox id="Test" runat="Server" />

OR

B. Dim Test AS new WebControls.TextBox
Test.ID = "Test"
Page.Controls.Add(Test)

Regards
Krister
 
Krister said:
What is the optimal way to create a webcontrol? Is it in the aspx-page
or in the code-behind (A or B)?

A. <asp:TextBox id="Test" runat="Server" />

OR

B. Dim Test AS new WebControls.TextBox
Test.ID = "Test"
Page.Controls.Add(Test)

Regards
Krister

Only use B if you don't know at design time how many controls
you'll need at runtime.

With A it's much easier to control all the properties, events, postback,
etc.
 
Back
Top