M
Miles Thompson
Hi !
I'm trying to optimize a slow page.
The page contains multiple instances of the same UserControl, and the
profiler is telling me that the following line is slow ..
CSWWItem myWWItem = (CSWWItem) LoadControl("../CSControls/CSWWItem.ascx");
It occurs to me that maybe LoadControl is recompiling the ascx page every
time its called. If so, my question becomes.. is there a way to manually
compile and then create instances of the controls from the compiled
version??
Thats the short version, heres the longer one, with more details.
The thing is I have a user control (which uses code behind) with an ascx
file that starts off like this.
<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="CSWWItem.ascx.cs"
ClassName="CSWWItemControl"
Inherits="CreditSights.CMS.CSControls.CSWWItem" %>
As I understand it, when ASP.NET needs to load this user control it compiles
the ascx code and creates a class, with class name "ASP.CSWWItemControl" and
presumably this goes into some dynamically created "ASP" assembly somewhere.
(If I don't specify the classname attribute, it creates an instance of type
"ASP.CSWWItem_ascx").
In other words if I do this..
object nextItem = LoadControl("../CSControls/CSWWItem.ascx");
...then the instance "nextItem" is of type "ASP.CSWWItemControl".
What I would rather do is something like this..
ASP.CSWWItemInclude nextItem = new ASP.CSWWItemControl();
nextItem.InitializeAsUserControl();
nextItem.Property1 = "value1";
Page.Controls.Add(nextItem);
At least, I guess that then I would *know* that it was only compiled once,
and therefore, hopefully faster than the LoadControl(".") way.
Problem with that is, I can't add a reference in the code behind to the
"ASP" assembly.. I mean I don't even know where it is, and have a feeling
that I shouldn't do that anyway.
Alternatively is there a way to compile my own ascx file into a type that I
can then "CreateInstance" on? Anybody know how to do that? I'm willing to
sacrifice auto-compilation for the speed benefit in this case.
Any suggestions much appreciated. Thanks in advance !
I'm trying to optimize a slow page.
The page contains multiple instances of the same UserControl, and the
profiler is telling me that the following line is slow ..
CSWWItem myWWItem = (CSWWItem) LoadControl("../CSControls/CSWWItem.ascx");
It occurs to me that maybe LoadControl is recompiling the ascx page every
time its called. If so, my question becomes.. is there a way to manually
compile and then create instances of the controls from the compiled
version??
Thats the short version, heres the longer one, with more details.
The thing is I have a user control (which uses code behind) with an ascx
file that starts off like this.
<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="CSWWItem.ascx.cs"
ClassName="CSWWItemControl"
Inherits="CreditSights.CMS.CSControls.CSWWItem" %>
As I understand it, when ASP.NET needs to load this user control it compiles
the ascx code and creates a class, with class name "ASP.CSWWItemControl" and
presumably this goes into some dynamically created "ASP" assembly somewhere.
(If I don't specify the classname attribute, it creates an instance of type
"ASP.CSWWItem_ascx").
In other words if I do this..
object nextItem = LoadControl("../CSControls/CSWWItem.ascx");
...then the instance "nextItem" is of type "ASP.CSWWItemControl".
What I would rather do is something like this..
ASP.CSWWItemInclude nextItem = new ASP.CSWWItemControl();
nextItem.InitializeAsUserControl();
nextItem.Property1 = "value1";
Page.Controls.Add(nextItem);
At least, I guess that then I would *know* that it was only compiled once,
and therefore, hopefully faster than the LoadControl(".") way.
Problem with that is, I can't add a reference in the code behind to the
"ASP" assembly.. I mean I don't even know where it is, and have a feeling
that I shouldn't do that anyway.
Alternatively is there a way to compile my own ascx file into a type that I
can then "CreateInstance" on? Anybody know how to do that? I'm willing to
sacrifice auto-compilation for the speed benefit in this case.
Any suggestions much appreciated. Thanks in advance !