default focus on asp.net button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akg
    New Member
    • Jan 2007
    • 19

    default focus on asp.net button

    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="javas cript" type="text/javascript">
    document.getEle mentById('txt') .focus();
    </script>
    </body>
  • nguyen1105
    New Member
    • Jan 2007
    • 5

    #2
    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="javas cript" type="text/javascript">
    document.getEle mentById('txt') .focus();
    document.getEle mentById('btn2' ).focus();
    </script>
    </body>

    Comment

    • akg
      New Member
      • Jan 2007
      • 19

      #3
      Originally posted by nguyen1105
      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="javas cript" type="text/javascript">
      document.getEle mentById('txt') .focus();
      document.getEle mentById('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

      Comment

      • nguyen1105
        New Member
        • Jan 2007
        • 5

        #4
        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.

        Comment

        • enreil
          New Member
          • Jan 2007
          • 86

          #5
          Do you have the tab order set correctly?

          Originally posted by akg
          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

          Comment

          Working...