Button to set the default focus

Source: Internet
Author: User

 

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.