Last post Jan 25, 2017 07:26 PM by KathyW
Jan 25, 2017 08:42 AM|jimmy69|LINK
for one of our project we THINK to develop this application without design the layout ...
we think just add all controls, design , and so on on the code behind :
// Create dynamic controls here.
// Use "using System.Web.UI.WebControls;"
TextBox1 = new TextBox();
TextBox1.ID = "TextBox1";
TextBox1.Style["Position"] = "Absolute";
TextBox1.Style["Top"] = "25px";
TextBox1.Style["Left"] = "100px";
TextBox2 = new TextBox();
TextBox2.ID = "TextBox2";
TextBox2.Style["Position"] = "Absolute";
TextBox2.Style["Top"] = "60px";
TextBox2.Style["Left"] = "100px";
this.TextBox1.TextChanged += new System.EventHandler(this.TextBox_TextChanged);
this.TextBox2.TextChanged += new System.EventHandler(this.TextBox_TextChanged);
for me, it's too bad and we loose many time ...and perhpas take time when we run the application because the design isn't know ...
but some people with more experience than me , can tell me the advantage or disavantage of using dyanmic coding ?
thanks a lot
Jan 25, 2017 09:22 AM|Mikesdotnetting|LINK
I cannot think of one single good reason to do this.
Jan 25, 2017 11:56 AM|PatriceSc|LINK
ASPX pages are turned into code so you basically just write by hand what could be expressed as markup.
You could have a look at
https://msdn.microsoft.com/en-us/library/cc488545(v=vs.100).aspx which inspect your model to generate pages. You can still customize at will as needed so it would allow a two step process if it can be useful to you (ie quickly have basic stuff up and running
and customize where needed).
You also have scaffolding Tools as nuget packages or you could create your own T4 templates or even use SQL queries or whatever to generate some code (or markup) from your data rather than typing that by hand and use that as a starting point...
Jan 25, 2017 07:26 PM|KathyW|LINK
Ditto what Mike said. Dynamically creating the page, or parts of the page, makes sense only when you actually don't know what the page content will be, and will be changing it based on something the site visitor does, or based on changes made in a database
that drives the page. There is no reason to incur the overhead of dynamically creating parts of the page that you know, at design time, will be there. Simply put them in the page (or View if you are using MVC), and style them appropriately with CSS.