Click here to Skip to main content
15,900,816 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,


When I Click the button validation is working,
While press enter button validating is not working
How to solve this problem.



If I enter the button automatically code executed and goes to code behind.
Error Is:
Conversion failed when converting the varchar value '1775we' to data type int. 



Thanks in advance.
Posted
Comments
ZurdoDev 29-Jul-13 10:16am    
You'll need to post your relevant code. Pressing Enter fires the default submit for the form so you must have a different one defined.
ZurdoDev 29-Jul-13 10:20am    
However, you should not rely just on client side validation. You should always validate server side as well because client side can be hacked.
venkateshCST 30-Jul-13 2:53am    
If you are working on server side validation then you need to use validation group for button which need to be similar of validation group assinged to validation control

1 solution

Either you can do this

C#
this.Form.DefaultButton = this.btnId.UniqueID;


or

Using Javascript:
JavaScript
function clickButton(e, buttonid)
{

  var evt = e ? e : window.event;

  var bt = document.getElementById(buttonid);

  if (bt)
  {
      if (evt.keyCode == 13)
      {
            bt.click();
            return false;
      }
  }
}




In CoeBehind

C#
ContentPage.Attributes.Add("onkeypress", "javascript:return
clickButton(event,'" + btnSearch.ClientID + "');");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900