Monday, 27 June 2011

Call defalut button click in text box enter button click by JavaScript


//JavaScript

function SaveUserDefaultButton(event)
{   
    try
    {
        // Set default button on press of enter key.
        if (event.keyCode==13)
        {  
            document.getElementById("btnOK").click();   
                   
            if(window.ActiveXObject)
            {
                event.returnValue=false;
                event.cancel = true;
            }
            else
            {
                event.preventDefault();
            }
        }
    }   
    catch(err){}
}

//Code behind (.cs)
this.txtFirstName.Attributes.Add("onKeyPress", "JavaScript:SaveUserDefaultButton(event);");

No comments:

Post a Comment