Creating controls at runtime or designtime

V

Varangian

Hello

is creating controls at runtime the same as designtime ?

will a page be faster if controls are created at designtime rather than
at runtime ? If so why ?

thanks :)
 
A

Arundhati Anavekar

I personally do not agree that there will be any performance difference
between design time controls and the server side controls executed by
ASP.NET/.NET.

Ultilmately, all controls has to be allocated at runtime and executed.


The differences may vary in use. Design time controls are easy to use,
matainence, where as dynamic controls are flexibile but should manually
maintain the view state persitence, child controls, etc.

If designed for specific functionality, dynamic controls can be
designed to provide faster access and/or with less memory footprint.

This can be a topic of contreversy but I prefer to distingush this way.

Hth,
Aru
 
S

Steve C. Orr [MVP, MCSD]

I agree with Arundhati.
Performance is not the main reason to go with design time controls because
there is little to no difference in performance.
Maintainability is the prime reason to go with design time controls whenever
possible - except maybe for unusually gigantic projects.
The code for creating and working with controls at runtime is much more
complex than the drag and drop simplicity of design time control editing.
 
B

bruce barker \(sqlwork.com\)

all controls are created at runtime. when the page is compiled, the compiled
code is just statments to create the controls at runtime.

take simple page:

<html>
<body>
<form runat=server>
<asp:button id=submit runat=server>
</form>
</body>
</html>

when the page is compiled, the init code for the page class will contrain
code like:

HtmlGenericControl ctl;
ctl = new HtmlGenericControl();
ctl.InnerHtml = "<html><body>";
Page.Controls.Add(ctl);
Form frm = new Form()
Button btn = new Button()
btn.Name = "submit";
frm.Controls.Add(btn);
Page.Controls.Add(frm);
ctl = new HtmlGenericControl();
ctl.InnerHtml = "</body></html>";
Page.Controls.Add(ctl);

-- bruce (sqlwork.com)
 
G

Greg Young [MVP]

There will be a very slight difference ...

I will not call them "Design Time" controls as they can also be setup in
html by hand and the same items here apply.

As Bruce points out, eventually the page is converted into a form that is
dynamically creating controls (it generates a class representing the work to
be done).

When you are dealing with dynamic controls in the code behind, the
compilation has already been done and is in your .dll, therefor the first
time the page is hit a compilation of that information is not needed. Of
course ASP.NET caches this information for the second time the page is hit
so this difference only really applies the first time the page is hit.

The fact that it is compiled as does also offer some benefits. You can
change code in the .aspx (.ascx) and it will be recompiled on the next page
hit as opposed to having to recompile the entire application.

As for maintainability I would lean towards the dynamic controls as many
techniques can be applied to them that cannot be applied to html based
controls (example: design patterns such as factory and decorator).

Cheers,

Greg
 
V

Varangian

oh a really big thanks for you all ... I was unsure of the difference
... I had to ask it here :) thanks again. I'll go for dynamic controls
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top