tags:

views:

25

answers:

2

Hi, I am facing a problem that's driving my crazy for sometime. I have an asp .net mvc page(.ascx). This view has a form which can be ajax submitted to a controller action. I have an ajax submit button that posts the form.

In the view I have some if conditions as follows

 If(Model.SampleID.HasValue) 
{
  
    alert('sample created');
    alert('');
  
}

This code works fine when I hit the ajax submit button, I mean the javascript gets executed. But when I hit the enter key, the same post happens but the javascript code is not executed at all. I don't know why this happens.

Any thoughts or comments?

A: 

Just a thought. Could be that your ajax submit button is only binded to the click event. If so u will have to bind it to the keypress event.Yes its better that you post the html.

Kanishka
A: 

put the following code in in the document.ready() function

$("input").keydown(function(e){
    if(e.which==13)
    {
        //Your Submit Method
    }
});
Dilan Chandima