Validate webform onClick event of LinkButton in ASP.Net

2.8k Views Asked by At

In Asp.net I am using this JQuery validation plugin.
It works perfect for <asp:Button> control. But if I use <asp:LinkButton> it does not validate the form and allows it to call code behind method.

Why is this happening? How can I able to validate form onClick event of <asp:LinkButton>?

EDIT: The problem with <asp:button> is we cannot able to add image on it. Check this.

2

There are 2 best solutions below

2
On BEST ANSWER

The simple solution is to add a click function that returns false if the form is not valid:

$("#<%= tb.ClientID %>").click(function() {
       return $('form').valid();
})

more : ASP.NET LinkButton / ImageButton and JQuery Validate? Hope this will help !!!

0
On

You can use OnClientClick in order to call your client method

Link : http://msdn.microsoft.com/fr-fr/library/system.web.ui.webcontrols.linkbutton.onclientclick.aspx

Nota : OnClick is for ServerSide, OnClientClick is for Client Side