Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 16th, 2004, 03:59 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default Setting Focus

I am very familiar with the traditional body onLoad event to set focus to a form element in JavaScript. However, in .NET, I am dealing with elements that have no name per se, just an id value.

How do I use this to set focus when a page loads? It's a standard login page, and I'd like to have the Username field get the focus on load.

Thanks in advance.

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old January 16th, 2004, 04:11 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You can get the unique ID that .net will assign to a control with "<control>.ClientID". This will give you the value that will go in the id attribute of the HTML tag. Use the getElementById() document method to access the HTML object...

document.getElementById('<output of .ClientID>')

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old January 16th, 2004, 04:28 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It worked perfectly. I swear, intellisense has me whipped. The focus method is not in the intellisense list for
document.getElementById("controlname")


Thanks again. Enjoy your long weekend.

Colonel

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old January 17th, 2004, 01:07 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

It shouldn't be. getElementById could return any element of the document object model. This could be a span, form, input, button, image, div, anything that has an ID. Many of those can't take focus.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old January 19th, 2004, 09:31 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I see.

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting Query Focus. eusanpe Access VBA 4 June 4th, 2008 10:20 AM
Setting Text Box Focus sathish_reddy ASP.NET 1.0 and 1.1 Professional 1 November 22nd, 2006 02:26 AM
Setting Focus on a Sub Form Brendan Bartley Access 1 August 8th, 2005 02:41 AM
Setting the Focus BSkelding ASP.NET 1.0 and 1.1 Professional 1 May 12th, 2005 01:40 PM
Setting focus to a web control textbox? hilda ASP.NET 1.0 and 1.1 Basics 2 November 1st, 2003 11:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.