Thursday, January 24, 2008

Handle default button event in Asp.Net 1.1.

Asp.Net provide the easy way to handle default button event,with asp.net you have write your own code to fire the button event on "Enter" key hit.
Here is two method to handle it.
1)Write this code on page load event.
Page.RegisterHiddenField("__EVENTTARGET", btnSearch.ClientID);

2)txtSearch.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('"+btnSearch.UniqueID+"').click();return false;}} else {return true}; ");

Here
txtSearch is the name of textbox and btnsearch is the asp button.

No comments:

Post a Comment