Stopping client side validation and postbacks

A couple of ways to stop client side validation firing, especially when using non controls:

Set the onclick event of the image/button etc to be onclick=”return false;” then instead of using the onclick event to fire a method, use the onmouseup event instead i.e. onmouseup =”javascript:do originalmethod(this);”

This will stop the page posting back but will fire the javascript method for the control in question. This comes in useful if you have a contact form with validation and a separate control i.e. for directions where you can enter a postcode and use javascript to fire off google maps in another page.

Redirect your user to their starting point when validation errors occur

Ever had a long webpage with validation that fails on postback but returns the user to the top of the page instead of where you want them?

Annoying isnt it. Well in .Net Framework 2.0 (yes it’s been there a while now), you can use the property:

Page.MaintainScrollPositionOnPostBack = true;

Well this will force the user to be returned back to the last point they clicked i.e. could be a control, button, checkbox etc

Very useful and helps with improving the user experience, something we should all be striving for!