Solved

How to set focus on a button?

Posted on 2008-10-28
8
2,760 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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 look for a specific file type in a local or remote server directory using PHP.

734 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