|
|
|
ASP.NET doesn't provide a built-in method for giving a control the input focus when the page loads. In fact, you can assign the TabIndex properties to controls on a page, but you can't use this property to set the initial focus on a control of your choice.
The following procedure provides you with the ability to do exactly this |
Click here to copy the following block | Sub SetControlFocus(ByVal ctrl As Control) Dim code As String = String.Format("<script language='javascript'>" & _ "document.getElementById(""{0}"").focus();</script>", ctrl.ClientID) ctrl.Page.RegisterStartupScript("SetControlFocus", code) End Sub |
As you see, the procedure inserts a line of JavaScript that runs after the page has been loaded, and that gives the focus to the control you pass as an argument. Because the Page object is retrieved as a property of the control, you can store this routine in any module of your ASP.NET application. You typicall call this procedure from the Page_Load event: |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|