none
How to set focus? RRS feed

  • Question

  • Hello

    In the MSDN tutorial here: https://msdn.microsoft.com/en-us/library/ms178232.aspx MSDN suggests the following to set focus in vb.net:

    Protected Sub Page_Load(ByVal sender As Object, _
        ByVal e As System.EventArgs)
        TextBox1.Focus()
    End Sub

    In my TextBox, I have:

    <asp:TextBox ID="user_name" runat="server" CssClass="textbox" Placeholder="Name" required="required"></asp:TextBox>

    How may I set focus, please, to TextBox ID="user_name"?

    Thank you.

    Saturday, December 2, 2017 7:44 PM

All replies

  • For this and any ASP.NET questions https://forums.asp.net/

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Proposed as answer by Frank L. Smith Saturday, December 2, 2017 8:01 PM
    Saturday, December 2, 2017 7:50 PM
  • OK, thanks Karen
    Saturday, December 2, 2017 8:17 PM
  • Thanks for your email today.

    This works where user_name is the ID of the name field in the aspx page:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
            user_name.Focus()
    
            LblDate.Text = ReturnDate()
    
        End Sub
    Regards

    Thursday, December 21, 2017 8:21 AM