Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics 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 October 31st, 2003, 04:48 PM
Registered User
 
Join Date: Oct 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Setting focus to a web control textbox?

Here's a real newbie question --
How can you set the focus to a web control textbox in asp.net server-side code? Depending upon what the user enters in a textbox, I'd like to set the focus to one of two other textboxes.

Client-side javascript works onload to set the focus but I want to set it at runtime and there is no textbox.focus().

Thanks for any help!
 
Old October 31st, 2003, 05:05 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Hilda,

There is indeed no TextBox.focus() as it wouldn't make much sense on the server (although I can imagine that a Server-side .focus() method would be able to send JavaScript to the browser. Maybe that's something for ASP.NET 2)

You'll need to emit some JavaScript to the client yourself that sets the focus from a function at the end of the file, or through the onload handler of the page.

Take a look at the RegisterClientScriptBlock and the RegisterStartupScript methods in the MSDN help. These methods allow you to send JavaScript to the browser.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old November 1st, 2003, 11:14 AM
Registered User
 
Join Date: Oct 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, I see. Thanks! It's really just a matter of setting the client-side event handler on a web control.

You can also set the handler by writing the client-side script in the html and then in the code behind in the Page_Load write:
webcontrolname.Attributes.Add("eventname","client-side_function();")









Similar Threads
Thread Thread Starter Forum Replies Last Post
Tip: Setting focus on login control jimibt BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 April 16th, 2007 01:50 PM
Set focus on web control vivekshah ASP.NET 1.0 and 1.1 Professional 1 June 18th, 2006 11:55 PM
set Focus to web control in Web form vivekshah C# 1 June 17th, 2006 03:25 AM
Setting Focus on a Text Box in a Web Form vbmazza VB.NET 1 May 4th, 2005 09:19 AM
Trouble setting focus in textbox on tabpage katsarosj VB.NET 2002/2003 Basics 2 April 6th, 2005 11:22 AM





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