Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I have found your site brilliant. What makes it good are the people that contribute to the site..."

Geography

Where in the world do Tek-Tips members come from?
JScannell (Programmer)
9 Feb 12 10:05
I'm not sure where to post this so if it needs to go somewhere else, let me know and I will re-post it there.

have you ever wanted to set initial focus to a specific control on a web form?  I have! And it took me a lot of digging around to come up with the solution.

In my case, I have a master page and a content page.  I need to set the initial focus to a text box named 'lkpLoginname'.  here's my code that gets placed in the Page_Load event of the page:

      If IsPostBack then Exit Sub

      '
      ' Initial entry.  Set focus to the windows ID text box
      '
      pnlEditEmps.Focus()

      Dim mainform As HtmlForm = DirectCast ( Master.FindControl      ( "Form1"        ), HtmlForm )
      Dim username As TextBox  = DirectCast ( pnlEditEmps.FindControl ( "lkpLoginName" ), TextBox  )

      If mainform IsNot Nothing AndAlso username IsNot Nothing Then
          mainform.DefaultFocus = username.UniqueID
      End If

The master page has a <form> and content page is wrapped with a panel.

If you don't have a master page, then you need a form element on your web page with a panel wrapped around it.  I was able to do this on a popup window and the code that worked is as follows:

      If IsPostBack then Exit Sub

      '
      ' Initial entry.  Set focus to the windows ID text box
      '
      Dim mainform As HtmlForm = DirectCast ( pnlWrapForm.FindControl ( "Form1"        ), HtmlForm )
      Dim username As TextBox  = DirectCast ( pnlWrapForm.FindControl ( "lkpLoginName" ), TextBox  )
      If mainform IsNot Nothing AndAlso username IsNot Nothing Then
          mainform.DefaultFocus = username.UniqueID
      End If


Sincerely yours,

Jerry Scannell
 

tcsbiz (Programmer)
9 Feb 12 11:49
How about creating a FAQ if there isn't one already?

I keep trying to do something about my procrastination but I keep putting it off until tomorrow.

JScannell (Programmer)
9 Feb 12 11:59
How do you do that?

Jerry Scannell
 

jbenson001 (Programmer)
9 Feb 12 12:13
Click the FAQs tab.
Go all the way to the bottom of the page to create a new one.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close