Loading Controls Dynamically

G

Guest

Hi -

I am seeing some performance degradation when I am loading a control
dynamically onto a page with multiple other dynamical controls using
Page.LoadControl versus dragging and dropping it onto an individual page.

Page1.aspx.cs
UserControl uc = Page.LoadControl("../UserControls/UserControl1.ascx")

Page2.aspx
<%@ Register TagPrefix="uc1" TagName="UserControl1"
Src="../UserControls/UserControl1.ascx" %>
<HTML>
<HEAD></HEAD>
<BODY>
<form id="StrategicReports" method="post" runat="server">
<uc1:UserControl1 id="UI1" runat="server"></uc1:UserControl1>
</form>
</BODY>
</HTML>

Page2.aspx renders the control much faster than Page1.aspx. Page1.aspx does
do some work in trying to identify which control to load but this still does
not account for the performance hit. Any ideas what is going on here? Is
there some other way to dynamically load the user control, say by adding a
"Reference" in Page1.aspx? Any help will be greatly appreciated.

Thanks in advance.
Kan
 
K

Karl Seguin

This shouldn't be a surprise...one is loading the control at runtime, the
other at compile time. It's slower, but it shouldn't be hugely slower (ie,
only noticable when profiling).

Server controls load considerably faster than user controls...but that's
really your only option..

Karl
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top