Dynamic Controls Without Doubling Processing Overhead

D

Dave Williamson

When a ASPX page is created with dynamic controls based on what the
user is doing the programmer must recreate the dynamic controls again
on PostBack in the Page_Load so that it's events are wired and are
called like a static control.

Here is the problem that I need to solve. The processing overhead
that occurs to determine what dynamic controls need to be added
involves business logic and a query or queries of data in a sql server
database. I would like to stop querying the database on every
PostBack to cut the processing in half (once for the page_load wireup
and once for the creation of new dynamic controls on the page to be
sent back to the user).

Imagine a web page that creates an table with embeded asp hyperlink
buttons based on a user's selection of criteria in a combo box. The
hyperlink has an event handler that does stuff. If the user clicks on
a hyperlink it will not fire the event handler unless the entire table
with hyperlinks is re-created on page_load. This re-creation of the
entire table is a waste of processing just to execute the one
hyperlink's event.

Any ideas on how to save this processing?
 
K

Karl

Dave,
Quickly I can think of two options.
First off, when you run your business logic and determine which controls
need to be dynamically loaded, you can save the result of that business
logic in the viewstate, which @ postback you can retrieve and reload the
controls. True, you still need to reload all the controls, but from what
you are saying, the performance issue comes with the business logic not the
reloading.

Alternatively, on postback you can take a peak at __EVENTTARGET in
Request.Form (Request.Form["__EVENTTARGET"]) and from that you might be able
to skip reloading the controls and skip directly to the hyperlink event (it
won't get called, but you'll know which control fired the postback and can
call the correct event).

Karl
 
R

Rocky Moore

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