You have a mistaken idea of how to setup validation. Do NOT attempt to
validate in Page_Load. Page_Load is run before your post back event handler
(the button's Click method). The post back event handlers are where you run
validation. In fact, the button automatically calls Page.Validate() for you
unless you set its CausesValidation property to false.
You should not attempt to save any data within Page_Load either. So in your
post back event handler, the following should occur:
1. Validation. Again its automatically for buttons that have
CausesValidation=true
2. Check Page.IsValid. If true, save or take whatever action needed on the
data.
FYI: You should assume that all browsers will not run the client-side
validation code. After all, users can turn off javascript in IE. It is
essential that you write server side validation code always. Microsoft
designed validation to work that way.
I have built a replacement to Microsoft's validation, Professional
Validation And More (
http://www.peterblum.com/vam/home.aspx). Its 22
validators support client-side validation on IE, IE/Mac,
Netscape/Mozilla/FireFox, Opera 7, and Safari. It overcomes numerous other
limitations that cause users to write custom code and develop hacks. It
includes a conversion utility to migrate from Microsoft validators.
--- Peter Blum
www.PeterBlum.com
Email:
PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
<in*******@hotmail.com> wrote in message
news:a8*************************@posting.google.co m...
Hi
How can I prevent an event (eg button click) from happening from
within page_load?
The reason is that I want to make my existing application work for
netscape, for which there are no client side validations.
So I thought to put something like the following in the superclass of
all UI pages:
public sub page_load
me.validate()
if not me.isvalid() then
'code to prevent the event to execute goes here.
end if
end sub