How to disable Enter key pressed inside TextBox to avoid submission or postback through code behind?

 Posted by vishalneeraj-24503 on 7/9/2014 | Category: ASP.NET Interview questions | Views: 1967 | Points: 40
Answer:

Visual Studio gives us a warning message when we add onkeydown event.But it's just a warning so we can ignore.So to avoid this warning,we can also disable submission from code behind as:-
txt_emp_first_name.Attributes.Add("onkeydown","return (event.keyCode!=13);");

//OR
txt_emp_first_name.Attributes.Add("onkeydown","prevent_submission();");

Abobe return code should be written inside prevent_submission() js function.


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response