Using the Enter key to trigger the event of a specified button makes it easy for us to operate. After entering some forms, we only need to press enter to respond accordingly. It is easy to implement this function in Asp.net.
First, convertCodeView, add the following Javascript script in HTML.
Function submithuicheevent (button)
{
If (event. keycode = 13) // 13 indicates the Enter key.
{
Event. returnvalue = false;
Document. All [button]. Click ();
}
}
In the design view, double-click the page_load event on the page and add the following code to it.
Private void page_load (Object sender, system. eventargs E)
{
Textbox1.attributes. Add ("onkeydown", "submithuicheevent (button1 );");
}
This method registers an onkeydown event for the text box in the C # language. In fact, you can also directly write the following in HTML:
<Input name = "textbox1" type = "text" onkeydown = "submithuicheevent (''button1');"/>
These two methods have the same effect. Writing in the C # language will eventually generate the second code in HTML.
At last, write the processing code you need in the click event of button1, delete a record, or save the data to the database. You can add it as needed.