bypass an event because server side validation failed

I

interuser

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
 
P

Peter Blum

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: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 
E

Enrique Santa Cruz

Check the page post back in the page load if it's false then the page load
has triggered on the first page load if it's true then the page load has
triggered on a post back event.
if(Page.IsPostBack != true)
{
Globals.Account = true;
Globals.Navigation(this, Globals.Parameter(this, "mi"),
Globals.Parameter(this, "si"), Globals.Parameter(this, "ni"),
Globals.Parameter(this, "ln"));
this.CurrentCulture =
System.Globalization.CultureInfo.CreateSpecificCulture(Session["Language"].ToString());
Browser.Accept = "text/*";
Menuloader(null);
Traductor(null);
Visualization(null);
RightPane.Controls.Add(Page.LoadControl("~/controls/search.ascx"));
string win = "false";
Rx.Attributes.Remove("onsubmit");
Page.RegisterHiddenField("__EVENTTARGET", "Submit");
Rx.Attributes.Add("onsubmit","javascript: validation("+ win +");");
}
Session["UrlRedirect"] = Request.Url.ToString();
Enrique.
 

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,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top