Default focus in ASP. NET and response to the carriage return key

Source: Internet
Author: User

ASP. net1.1:

Let the text box focus as soon as it is opened on the page:

Page. registerstartupscript ("Focus", "<script language = JavaScript & gt; document. All ('text control id'). Focus () </SCRIPT> ");

Press enter to trigger the specified button event: when the focus is on the password box, press enter to trigger the btnok button event

In the pageload event:
Txtpassword. Attributes. Add ("onkeydown", "submitkeyclick ('btnok ');");

In HTML:
<Script language = "JavaScript">

Function submitkeyclick (button)

{

If (event. keycode = 13)

{

Event. keycode = 9;

Event. returnvalue = false;

Document. All ('btnok'). Click ();

}

}

</SCRIPT>
Medium 2.0:

<Form ID = "form1" runat = "server" defaultbutton = "btnquery" defaultfocus = "txtusername"> </form>

 

3. As the browser is constantly changing, compatibility has become a major issue. The above is no longer suitable for IE 8 and other browsers.

 

Currently, jquary is widely used. We recommend that you use jquary's $ ("# idname "). focus () is used to get the focus of textbox and so on. It is not only compatible with most browsers, but also highly secure.

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.