PreRender event question

M

Matt Jensen

Howdy all - and seasons greetings

Just wondering, I've recently discovered the PreRender event for .NET (both
for the page and for controls), which seems like a life saver for doing page
data loads that need to occur AFTER event handlers have fired, as well as
after page load and postback. Is this good, bad or common practice?

example

I've got a repeater on the page, and in the header of the repeater I've got
hyperlinks for sorting the repeater and dropdown lists for filtering it, and
therefore the repeater has (I think) to be bound AFTER the hyperlink-click
or dropdownlist-selection-change events, hence pre-render seems to be the
place.

Another case, in the 'job booking system' that I'm building, the job master
needs to be able to change between job master and job worker roles, hence a
role-changing dropdown list at the top of the page, and given the
DDL-selection change events I believe occur after page load, and given in my
case databinding needs to happen after pageload, postback, and after
DDL-selection-change events, PreRender seems to be the ONLY place I can use.
However I've really not seen much about the PreRender event, although there
seems to be a bit around if you're actually searching on the term PreRender.
So I'm slightly hesitant about using it just yet...

Would appreciate any thoughts

Cheers
Matt
 
E

Eliyahu Goldin

Matt,

Technically, you can databind in PreRender. But...

This event is the last stop before the page gets sent to the client. At this
stage it is already supposed to be fully bound, built, etc. You can do some
format changes, calculations, set final values of the page. That is what the
event for. Databinding here is out of place.

I seem to make difference between a page load and a postback. There is no
such a difference. A postback causes Page_Load event.

True, all change events handlers get called after Page_Load. But you don't
have to wait until the change event handler runs. Already in Page_Load event
you can read all control values, including the current selection of the
dlls. I use this approach in my programs. I hardly use any change events. It
is enough if you set AutoPostback=true, then any change will cause a
postback which will trigger Page_Load event in which you can read current
values of the ddls.

Eliyahu
 
K

Karl Seguin

Matt, i use PreRender is a similar fashion...not necessarily with binding,
but I could see that happening.

I have an user control which display an article information. The articleId
is passed in as a property. I'm linkbuttons to select which article to
display. My user control can't load the details in Page_Load because
that'll fire before my linkbutton's eventhandler has gone off. Instead, i
use prerender to fetch the article based on the passed in id and set a bunch
of Text properties.

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top