Results 1 to 3 of 3

Thread: Focus

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    469

    Focus

    Hello

    If I have

    Code:
    <asp:TextBox ID="user_name" runat="server"></asp:TextBox>
    as a form field in my aspx file, how would I declare user_name.Focus() here:

    Code:
    Private Sub contact_form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
            Dim user_name As String
    
            user_name.TextBox.Focus()
    
        End Sub
    I get an error here:
    Code:
    user_name.TextBox.Focus()
    because TextBox is not a member of String.

    I would prefer to use 'Focus' here and not in the aspx.vb file

    Code:
    <asp:TextBox ID="user_name" runat="server"></asp:TextBox>
    if that is possible.

    Thanks again

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: Focus

    You can use these lines in markup (caution i'm not sure if we get the textbox like that if we have a masterpage.I remember that we need to do something else, but did not look.You can always use Jquery though).


    Code:
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <script type="text/javascript">
        function GetF() {
            var f = document.getElementById('<%= TextBox1.ClientID %>')
            f.focus();
            
        }
    </script>
        <title></title>
    </head>
    <body onload="GetF()">
        <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>      
        </div>
        </form>
    </body>
    </html>
    If you want in the code, you can use like: user_name.focus() (do not use user_name.textbox.Focus())
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    469

    Re: Focus

    Many thanks, sapator - the vb.net code worked.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width