First, add the following method to the Code: // <summary>
/// Set the control that triggers the event when you press enter on the page
/// </Summary>
/// <Param name = "Ctrl"> control object that triggers the event </param>
Public static void SetEnterControl (System. Web. UI. Control Ctrl)
{
Page mPage = Ctrl. Page;
String mScript;
MScript = @ "<script language =" "javascript" ">
Function document. onkeydown ()
{
Var e = event. srcElement;
Var k = event. keyCode;
If (k = 13 & e. type! = "" Textarea "")
{
Document. all. "+ Ctrl. ClientID + @". click ();
Event. cancelBubble = true;
Event. returnValue = false;
}
}
</Script> ";
If (! MPage. IsClientScriptBlockRegistered ("SetEnterControl "))
MPage. RegisterClientScriptBlock ("SetEnterControl", mScript );
}
Then call this method in the pageLoad method and pass the Object Name of the default button.
This method is excerpted from multiple methods in the blog garden. I think this method is a good one. If you have a better method, you are welcome to recommend it.