c# - Performance difference when building a web form using controls vs placeholders -
i have large list of forms company wants online , require forms "locked" after user fills them out , comes view submission. there dozens of forms created using asp.net c# web forms, told pick last developer left off. created separate page viewing, submitting , editing forms, if change comes in, need make same change in multiple locations. create user control each form can use same page in 3 spots started think moving work to.
the first thing came mind doing enable/disable on fields , using css style displayed fields text. (and removing button save @ bottom when viewing) seems straightforward , move work making pretty form browser using js , css.
next, looked @ using literal followed input field, switching visibility hide input fields when user previewing submission. doubled number of controls on page knew input went control.
my third thought dynamically building page using placeholders , adjusting needed. looked nice because store fields , types in database, allowing quick ordering , changing form without needing touch code.
my first idea seems easiest difference in performance if .net needs build form 100+ controls versus dynamically building form? better build entire page (or of it) dynamically or have 100+ placeholders , build areas need dynamic? don't want people "sure, made easier modify form takes 20 seconds load page."
update 1:
taking karl-anderson's advice, ran tests. set 3 pages contained table first cell being text ("name:") , second cell being input (a textbox). straightforward here rows:
(1) controls:
<tr> <td> name: </td> <td> <asp:textbox id="textbox1" runat="server"></asp:textbox> </td> </tr> (2) multiple placeholders:
<tr> <td> name: </td> <td> <asp:placeholder id="placeholder1" runat="server"></asp:placeholder> </td> </tr> (3) single placeholder: , last one, had single placeholder on page , built table in codebehind using:
table tbl = new table(); (int = 0; <= x; i++) { tablerow tr = new tablerow(); tablecell td = new tablecell(); td.text = "name:"; tr.cells.add(td); td = new tablecell(); textbox txtbx1 = new textbox(); td.controls.add(txtbx1); tr.cells.add(td); tbl.rows.add(tr); } placeholder1.controls.add(tbl); where x number or rows add.
results:
i loaded page , refreshed 10 times, taking average time took page load using .net's trace:
(1) controls:
controls time (seconds)
10 0.002089
20 0.003204
30 0.004530
40 0.005943
50 0.006821
100 0.013542
150 0.020033
(2) multiple placeholders:
controls time (seconds)
10 0.002604
20 0.004419
30 0.006507
40 0.008509
50 0.011194
100 0.024640
150 0.039748
(3) single placeholder:
controls time (seconds)
10 0.003501
20 0.005794
30 0.008264
40 0.010616
50 0.013048
100 0.024158
150 0.032826
the time took load when comparing single control single placeholder went ~24.6% long @ 10 controls ~98.4% longer @ 150 controls. comparing multiple controls single placeholder, started off ~67.6% longer load time @ 10 controls ~63.8% longer @ 150 controls.
i'm going try working formview (as suggested jadarnel27) , i'll compare results.
(i performed these tests on intel xeon e5520 processor @ 2.26ghz)
Comments
Post a Comment