ASP. NET is used to develop a system in this section, and many minor problems are encountered. This is one of them.
When a page has several buttons, you need to set the default button focus.
Baidu has two methods:
I. Protected void page_load (Object sender, eventargs E)
{
This. Page. setfocus (button2 );
}
-------------------------------------------
Protected void page_load (Object sender, eventargs E)
{
This. Page. registerclientscriptblocK ("_ autopostback", "<SCRIPT type =" text/JavaScript "> function document. onkeydown () {If (event. keycode = 13) {document. getelementbyidx ('"+ button1.clientid + "'). click () ;}</SCRIPT> ");
}
The two methods have the same effect. Once the focus changes, it will go back to the last added button, so the effect is not good. When there are multiple buttons on the same page, the expected results are still not met.
Ii. In formCode, Use
Defaultbutton and The defaultfocus attribute is enough, for example
<Form ID = "form1"
Defaultbutton = "btnsubmit"
Defaultfocus = "textbox1"
Runat = "server">
When the page is loaded, the default button is btnsubmit, and the focus is on texbox1 by default.
Http://blog.sina.com.cn/s/blog_682b43bc0100zhde.html