1

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.

Community
  • 1
  • 1
Prasad Jadhav
  • 5,090
  • 16
  • 62
  • 80

2 Answers2

2

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 !!!

Community
  • 1
  • 1
christiangobo
  • 520
  • 1
  • 7
  • 19
0

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

Aghilas Yakoub
  • 28,516
  • 5
  • 46
  • 51