Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional 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 May 12th, 2005, 12:53 PM
Authorized User
 
Join Date: Mar 2004
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default Setting the Focus

Is there any way to programmatically set the focus to a control in a data repeater?

Currently I have a data repeater that binds to a dataset. Each item has a text box that can display text or allow the user to edit the values. Frequently, changing the text causes the page to perform a post back operation. I'd like to be able to have the cursor return to the text box that caused the change or perhaps the next text box in line. Any ideas?

Thanks.
 
Old May 12th, 2005, 01:40 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

There are a couple ways to approach this depending on what you are going to end up doing.

In you turn on smart navigation for the page, ASP.NET will automatically scroll the page and focus onto the control that was last active. However, based on what you said about the textboxes this might not work perfectly. Assuming that your postback is being caused by a textbox change even, you have to leave the textbox for that clientside event to fire, which then fires the postback. So your return focus might not be exactly where you want it.

In the second scenario you'll have to employ some fancy code-behind footwork. When you process the postback event of the text change you'll have to find the repeater item where that textbox exists. You should be able to ask for textbox.Parent (maybe more .Parents) and eventually work your way back to the repeater ITEM, where you can get the item index, and then the repeater itself, where you can get the next item (n+1). Then you can drill down into the item and find the textbox. Grab the textbox's ".ClientID", then you can use that in some javascript: document.getElementById("<value from clientid>").focus();

-Peter





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 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.