Solved

How to set focus on a button?

Posted on 2008-10-28
8
2,753 Views
Last Modified: 2012-05-05
hi all,
i set default focus on button B in my form, but when you click somewhere (eg. click empty space on the web page), the focus just moves to the first button A on the page. (note: the button B i set to default focus is the second button on the page). how can i set focus on this  button B when you first drop your mouse on this page?

i tried to rearrange the tab index to set Button B as the first index but it does not work. and i also tried the following methods:
1. <form id="form1" runat="server" defaultfocus = "ButtonB">,
2. In page_load, set
protected void Page_Load(object sender, EventArgs e)
    {
              ButtonB.Focus();  
     }
3. In page_load, set
protected void Page_Load(object sender, EventArgs e)
    {
              Page.setFocus("ButtonB");  
     }
ALL the above methods work only when you first load the page, but when you FIRST click the page/drop your  mouse on that page, the focus moves to the BUTTON A. How to solve this problem? help!!!!

thanks a lot
viola
0
Comment
Question by:viola123
  • 4
  • 3
8 Comments
 
LVL 1

Expert Comment

by:Nullable
ID: 22827681
you can use a Panel Control and drop your buttons in it
then use DefaultButton property from Panel control and insert ID of the default Button

0
 
LVL 1

Expert Comment

by:Nullable
ID: 22827712
Attention !

other Controls that need Default Button such as Text boxes also need drop in to The Panel
0
 
LVL 6

Author Comment

by:viola123
ID: 22827760
hi,
thanks, i will try it now.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 6

Author Comment

by:viola123
ID: 22827820
hi,
it doesn't work, still do the same way as what i described.
0
 
LVL 1

Expert Comment

by:Nullable
ID: 22827834
you want that a Button be a default ? yea ?
this solution do this

u can Bold the font of the default button for user attention


0
 
LVL 6

Author Comment

by:viola123
ID: 22827968
hi, but this is not fit the business requirement
0
 
LVL 15

Accepted Solution

by:
angus_young_acdc earned 500 total points
ID: 22829327
You could create a mouse click event, and everytime that is fired have the focus set to your button.
0
 
LVL 6

Author Comment

by:viola123
ID: 22863662
hi,angus_young_acdc:
thanks, that is a good idea.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question