1st Method
----------------------------
WRITE THE CODE IN PAGE LOAD OR IN ANY EVENT LIKE BUTTON EVENT.........
Page.RegisterStartupScript("SetInitialFocus", "<script>document.getElementById('" + txtFirstName.ClientID + "').focus();</script>");
txtFirstName= is the name of the control to focus
2ND Method
----------------------------
Easiest way to set a focus when web page is loaded
To set a focus when web page is loaded you can use a BODY onload event and javascript client code. Let say you have a web form with ID="Form1" with some controls, including a textbox named TextBox1. To set a focus to TextBox1 when page is loaded you can use this javascript code:
<body onload="javascript:document.Form1.TextBox1.focus();">
No comments:
Post a Comment