How to generate complex custom control

D

Dennis M

Hey everyone,

I am curious what the performance impact of a custom control would be if it
had a significant hierarchy of children. For example, 40 child controls, 5
levels deep, each control on average has 20 properties. What would be the
best way to implement such a thing?

The book I am reading uses templated controls and basically reconstructs the
entire hierarchy everytime page is accessed based on the tags in the .aspx
file, but books example only has 2 child controls. Would it make sence to
use xml configuration file instead of template elements? Would it be
possible to read the xml file once, build the hierarchy and then save it
somewhere, so that it is only regenerated when xml file changes? I was
thinking taking the root element and storing it in application cache, or
even serializing it to disk, but I am not sure if controls are allowed to be
reused for subsequent requests.

So anyone know the proper way such situation would be handled?

Oh yeah, I was thinking placing the whole thing into a user control and
making it cachable, but control would still be regenerated if it has to
process post-back events, right?

Thanks for any info

-- Dennis
 
S

Steven Cheng[MSFT]

Hi Dennis,

From your description, you're wanting do generate a complex custom control
which has huge amount of sub elements and also deep hierarchy. Since
normally all the server controls on the page will be reconstrucuted when
the page is requested and loaded on the serverside, you're wondering some
means to improve the performance, yes?

I think the behavior that a server control is recontructed at serverside
when processing its contaier page is unavoidable. Everytime the page is
processing on the severside, it'll first reconstructor the Control
hierarchy and mapping their viewstates to them(if is post back). If you
want to avoid this, one way is to use the Cache function in ASP.NET, and I
think the means that use xml configuration file to store the controls'
strucutre info and restructure the control whenever the file is modifed you
mentiond is reasonable. In ASP.NET 's serverside cache feature, there is
one means to help cache the page's output depend on a file on the
serverside , the page will be construcuted( all its controls) the first
time it is request , after that if we request the page again, the page's
ouput will be the plain html values which is output the first. And this
cache will remain until the dependent file is modified. For detailed info,
you can view the following reference in MSDN:

#ASP.NET Caching Features
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconaspcachingfeatures
..asp?frame=true

#@Caching Page Output with File Dependencies
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconcachingpageoutputw
ithfiledependencies.asp?frame=true

Also, if you don't want to cache a whole page. I think you can manually
implement the control's file denpendent caching in your control's
construcut code. For example, you can generate the control's structure and
render it out the first time and store the output in the Application.Cache,
and the cahe is file dependent, then the next time the control will check
the applcation cache, if exist retrieve the cache and output it rather than
reconstrucure the whole control. How do you think of this? Also, I think
we may wait for some one else's suggestions. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
D

Dennis M

Hey Steven,

Thanks for the response, I think I will end up some sort of variation
of what you suggested.

But what I was really curious about if instead of caching text
(control output as HTML), can I build the control object tree once and
then take the top object and put it into application cache. I've
tried something similar with a drop-down box that I initialized by
reading an XML file and it seems to be working, but I don't know if it
is legal, or what complication I could expect.

Actually as I am writing this, I just thought of one: if the control
hierarchy is shared and 2 users postback at the same time, the same
controls will probably be initialized with postback data, if there is
postback data. So that probably won't be good. But what if there is
no postback data and all control data members are common for all users
(and maybe changed at some point at the application level), then maybe
it is legal.

What do you think?

Another question to you or anyone who knows this. You probably can't
cache pure text HTML output if control has to process post-backs
because if you use the cache, objects don't get instantiated and
therefore they can't process the postbacks (or events), right?

Thanks,

-- Dennis
 
S

Steven Cheng[MSFT]

Hi Dennis,

Well, I agree with you on cached the control structure instances rather
than plain html string. Also that'll be ok if the control's structure is
shared by all users and won't be critical on personalization issues. In
addtion, as for the following issues on post back when caching the
htmloutput:
=========================
Another question to you or anyone who knows this. You probably can't
cache pure text HTML output if control has to process post-backs
because if you use the cache, objects don't get instantiated and
therefore they can't process the postbacks (or events), right?
=========================

Yes, this will cause the post back not work. I just forget this problem.
Thanks for your noticing.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 

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

Top