Is it possible to stop the page postback on any click event based on some validation
A:
if you mean doing it client-side (i.e. make it so that the page doesn't postback), you'll probably have to do it in Javascript.
just attach a click event JS function on whatever it is you want validated, and have it return false;
when you don't want it to postback to server-side ASP.NET.
Richard Neil Ilagan
2010-09-03 05:05:48
+1
A:
You can use client side validation of different kinds. With ASP.NET WebForms, the easiest way would probably be the built in validators (e.g: RequiredFieldValidator).
SirDemon
2010-09-03 05:06:14
A:
Answers above are correct. Here is another way to block postback.
Page.ClientScript.RegisterOnSubmitStatement(string key, string script)
We can prevent pages from postback at onsubmit event because:
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
Danny Chen
2010-09-03 05:18:45