473,465 Members | 1,897 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

default focus on asp.net button

19 New Member
Dear Friends,
I have a problem. In one of my asp.net form, I have two buttons 'reset' and 'submit' and approx 20 textboxes. through javascript, I am setting focus on first textbox. What I am seeing that cursor is blinking in the first text box, and my first button 'reset' also have focus. I want this focus should be on the second button but I am not able to do that. can somebody please help me on this. I am using asp.net 1.1. Other thing is that I have to use only asp:button and not html buttons. My code is like below:

<body MS_POSITIONING="GridLayout">
<form id="Banner" method="post" runat="server">
<asp:button id="btn1" Runat="server" Text="Button1"></asp:button>
<BR>
<BR>
<BR>
<asp:button id="btn2" Runat="server" Text="Button2"></asp:button><br>
<asp:TextBox id="txt" Runat="server"></asp:TextBox>
<BR>
<asp:TextBox id="Textbox1" Runat="server"></asp:TextBox>
<BR>
<asp:TextBox id="Textbox2" Runat="server"></asp:TextBox>
<BR>
</form>
<script language="javascript" type="text/javascript">
document.getElementById('txt').focus();
</script>
</body>
Jan 19 '07 #1
4 2906
nguyen1105
5 New Member
I have a problem. In one of my asp.net form, I have two buttons 'reset' and 'submit' and approx 20 textboxes. through javascript, I am setting focus on first textbox. What I am seeing that cursor is blinking in the first text box, and my first button 'reset' also have focus. I want this focus should be on the second button but I am not able to do that. can somebody please help me on this. I am using asp.net 1.1. Other thing is that I have to use only asp:button and not html buttons. My code is like below:

Hello,

If you want to set the focus on the second button, do the same trick that you did for the first text box. That means

<script language="javascript" type="text/javascript">
document.getElementById('txt').focus();
document.getElementById('btn2').focus();
</script>
</body>
Jan 19 '07 #2
akg
19 New Member
Hello,

If you want to set the focus on the second button, do the same trick that you did for the first text box. That means

<script language="javascript" type="text/javascript">
document.getElementById('txt').focus();
document.getElementById('btn2').focus();
</script>
</body>
you are right, 'btn2' gets focus but the problem is when you press the 'TAB' button then focus again shifts to 'btn1' which is not correct. focus should be on the second textbox.

Regards,
Amit
Jan 19 '07 #3
nguyen1105
5 New Member
Hello,

Because the focus is right now in Button2, if you hit on TAB, the focus will be shifted to the next control which is the TextBox and not Button1. I don't know why you can get such a behavior.
Jan 22 '07 #4
enreil
86 New Member
Do you have the tab order set correctly?

you are right, 'btn2' gets focus but the problem is when you press the 'TAB' button then focus again shifts to 'btn1' which is not correct. focus should be on the second textbox.

Regards,
Amit
Jan 22 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Shixx | last post by:
Hello, I have problem in my web application and my web form. I have 5-6 buttons (web controls) and when I have focus on some text box, always one button becomes default and got focus, and after I...
2
by: nic | last post by:
hey, I have an aspx page with some textboxes and 3 buttons. How can I set the defaultbutton? tkx Nic
2
by: Bratislav Jevtic | last post by:
hi, how to make some push button default on the form? for instance, I've got 2 buttons (Submit, Cancel). submit is on the left, cancel on the right side. on enter key pressed, cancel button is...
2
by: Sanjeeb Sarangi | last post by:
I have got a couple of Serverside Button Controls in a page. Each button performs different actions, e.g. Button1 performs Submit, Button2 performs Cancel etc. Now, I want the default button mapped...
2
by: makthar | last post by:
Thanks for taking the time to read this note Can anyone explain what went wrong and any ideas how to fix it I have a search page With three buttons few drop downs and a textbox. The search...
1
by: Lamine Darbouche | last post by:
Please Help, I have a form with multiple buttons "New User", "Delete User", "Save" buttons, when I access the form it selects the "New User" button by default, so when you hit the return key...
3
by: Marty McFly | last post by:
Hello, I have a control class that inherits from System.Web.UI.WebControls.Button. When I drag this control from the "My User Controls" tab in the toolbox onto the form, I want it to reflect the...
7
by: Zytan | last post by:
I want to set a control in a form to have the default focus. This is not the accept button -- that's set to a button when is 'clicked' when you press ENTER. I want a textbox to have the focus...
5
by: Zytan | last post by:
Is it possible (I doubt it) to have multiple default buttons in a form? I have several group controls in a single form, and when the focus is within one of the group controls, I want a specific...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.