Monday, 27 June 2011

Disable Enter Key press in a multiline text box Through JavaScript


//JavaScript

function DisableEnterKeyPress(event)
{
    if (event.keyCode==13)
    {       
        if(window.ActiveXObject)
        {
            event.returnValue=false;
            event.cancel = true;
        }
        else
        {
            event.preventDefault();
        }                           
    }
}

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

No comments:

Post a Comment