Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to set focus on a button?

Posted on 2008-10-28
8
Medium Priority
?
2,762 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
PowerShell Core for Advanced Linux Administrators

Understand advanced principals around Powershell Core with a focus on the Linux Administrator.  This course covers how to administer numerous environments across multiple platforms including Linux, Azure, AWS, and Google Cloud from a single shell instance.

 
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 1500 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

721 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