Where in the page lifecycle does validation occur?

P

paul.hester

Hi all,

I don't use auto postbacks on my web site to keep it javascript-free
and browser agnostic. Whenever there's a postback to my page I'm using
the Page_Load event to use the posted data for database updates.
However, the page hasn't been validated at this point. I can call
Validate() at this point, but this means the controls will be validated
twice.

At what point in the page lifecycle are the controls validated? When
would be the best time and place to use the posted data for a database
update, if not using auto postbacks? My current method doesn't seem
ideal.

Thanks in advance,

Paul
 
T

Teemu Keiski

Hi,

it happens just before postback events are raised (after Page_Load). In
practise, if you have a Button on Page which triggers validation, it happens
just before Button's Click event is raised. In the Button's Click event, you
could then just check Page.IsValid.
 
P

paul.hester

Thanks Teemu,

If I don't want to use button events (to avoid the need for javascript)
where's the best place to check if the posted data is valid and do
database updates, redirects etc.?

Thanks,

Paul
 
T

Teemu Keiski

Just before you need the data. generally you'd want to use events as they
help in keeping the page code structure clean. Otherwise you have code
centralized in one place trying to deal all cases.

Note that Js validation isnt that bad, you have server-side validation
backing it up in any case.
 

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,817
Latest member
DicWeils

Latest Threads

Top