Solved

How to set focus on a button?

Posted on 2008-10-28
8
2,745 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
 
LVL 6

Author Comment

by:viola123
ID: 22827820
hi,
it doesn't work, still do the same way as what i described.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now