AddOnPreRenderCompleteAsync and dynamically created controls

K

Keith Patrick

I'm running into a wall with a custom control that gets populated via
asynchronous I/O. Basically, my control takes its datasource and renders
some controls that have events (OnClick). However, there's the well-known
problem of dynamic controls not firing unless they are created during the
page's initialization, so OnPreRender is too late to create any dynamic
controls. That being the case, how can I populate a control asynchronously
(via Page.AddOnPreRenderCompleteAsync) that has events that can get fired?
 
B

Bruce Barker

for events to fire on postback, you need to recreate the dynamic controls at
onint. this means you should use a caching scheme to recreate them on
postback. on a render, you can still add controls on prerender fine (as
there are no postback events to manage).

-- bruce (sqlwork.com)
 
K

Keith Patrick

Hmm, I can see that working, but it's got some issues that may come up under
heavy usage, performance-wise. In my case, I've got the datasource
retrieval abstracted out to a provider, caching included such that any time
I say GetStuff(), it will be from the *current* file contents (cache updates
with the file), and populated on the first call of a page by any user
asynchronously. The thing that's causing me problems doing that is that I
should have logic in the initialization method that's only called when the
data is cached but I'm calling it asynchronously during pre-render when it's
not (and actually, I'm doing this in a masterpage, so I don't even have
access to an OnInit() as well). Things start getting messy when the
external file is changed after render but before postback; the cache is
flushed by the file watcher, so the postback OnInit will now make a
synchronous call to re-fill the cache, bypassing the page's async path.
What would be ideal is to be able to programmatically process postback
events again during the prerender step. I thought I had something along
those lines with Page.RegisterRequiresRaiseEvent, but I misunderstood the
method and wound up getting the last control created being reported as the
sender. Maybe something like Page.PersistForPostBack(...), or if the
ViewState would work with them (I tried and it didn't, although I haven't
ruled out that it's possible)
 
K

Keith Patrick

Heh...scratch that part about not having OnInit in a master page. I'd had
it implemented elsewhere, so it wasn't showing up in AutoComplete. I'm
looking at going back to storing viewstate for the control as my solution;
I'd disabled it to reduce pagesize, but I think it would be more correct for
me to store the stripped down structure in viewstate so I have something
that is consistent with what was build on prerender during rebuilding, thus
avoiding the cache coherency issue when the datasource is changed during
usage.
 
K

Keith Patrick

And just to show I can't ever make up my mind, I had an Avalon epiphany and
realized my control, which was merely rendering hierarchical data, is
logically just a TreeView with a very specialized visual tree (instead of
declaratively allowing <Setter Property="Template"/>, though, a WebControl
requires override Render(...))
End result? I'm subclassing TreeView such that I get to use the datasource
stuff MS already built into the infrastructure and let it take care of
repopulating the controls/wiring up events in the right time; I just worry
about defining a datasource the thing can use.
 

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,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top