Solved

How to set focus on a button?

Posted on 2008-10-28
8
2,747 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
The viewer will learn how to count occurrences of each item in an array.

932 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

10 Experts available now in Live!

Get 1:1 Help Now