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 March 13th, 2006, 02:11 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default Set Focus to Field in User Control

I have a web user control containing a postback enabled checkbox called chkBold. When this check box is clicked, postback occurs and focus on the check box is lost. I want to put focus back on the check box after the form refreshes but this code, contained in the code behind for the check box, isn't working:

RegisterStartUpScript("SetFocus", "<script>document.frmSurveyDefn.TitleStyle.chkBold .focus();</script>")

What is the proper format when referencing an object in a user control?
 
Old March 14th, 2006, 12:51 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

The names of the controls render differently when a user control renders. To check the name, run your page and do a view source.

What I did to test was I created a WebUserControl with 2 TextBoxes.. TextBox1 and TextBox1. My user control name is WebUserControl1.

To use your code and set the focus to TextBox1 I did this:
RegisterStartupScript("SetFocus", "<script>document.Form1.WebUserControl11_TextBox1.focus();</script>")

Notice how it names the textbox ... All you need to do is view the source of your page and change the code above accordingly.

Hope this helps..

Jim

 
Old March 14th, 2006, 04:20 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

I tried to get it to work but still had no luck. We're finally upgrading to V2 next week, and I understand that it supports a Setfocus method in the browser just like Windows applications. So I'm simply going to hold off until the upgrade and do it the right way. Thanks again!
 
Old March 14th, 2006, 05:53 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

ok good luck






Similar Threads
Thread Thread Starter Forum Replies Last Post
Set focus on a particular field after server side vinodonline2000 ASP.NET 2.0 Basics 1 March 6th, 2008 09:15 AM
USER CONTROL FOCUS PROBLME ......PLZ. HELP ME meerraj ASP.NET 1.0 and 1.1 Professional 1 February 28th, 2007 06:29 AM
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
Can't get focus on user control drb2k2 C# 2 December 15th, 2004 12:51 PM





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