We have a couple of WebDialogWindows, they all have some input fieldS and OK and Cancel buttons. The dialog is shown via client script and the OK/Cancel buttons are also handled by client script.
Now I want the OK button to behave as a default button, e.g. a user presses the enter key in any of the fields it must perform the OK action. How can I do this ?
Lex
You can use following code:
<input type="text" id="txtSearch" onkeypress="enterKeyPress(event);" />
<input type="text" id="txtSearchOne" onkeypress="enterKeyPress(event);" />
<script type="text/javascript" id="igClientScript">
<!--
function WebImageButton2_Click(oButton, oEvent){
alert("OK buttun clicked...");
}
// -->
function enterKeyPress(e)
{
// look for window.event in case event isn't passed in
if (window.event) { e = window.event; }
if (e.keyCode == 13)
document.getElementById('<%= WebImageButton2.ClientID %>').click();
</script>
Thanks, although it works, I was hoping for a simpler solution. Perhaps some enhancement to the WebDialogWindow that allows setting a default action for enter and escape.