0

At the top of my aspx page is a searchbox. I want this textbox to have focus when the page loads, but I also want it to have some place holder text so the new users know what it does. My problem is when the box has focus the placeholder text dissapears. How do I get both simultaneously?

I think the answer is jQuery, but I'm not to familiar with jQuery so I don't know how this would be done.

Thanks for the help =)

    private void Page_Load(object sender, System.EventArgs e)
    {
        LoginSearch.Focus();
        ...
        }
    }

-

<asp:TextBox ID="LoginSearch" placeholder="Login Search" runat="server" ToolTip="Login Search" OnTextChanged="LoginTextChanged" AutoPostBack="True" TabIndex="0"></asp:TextBox>
Brian H
  • 1,033
  • 2
  • 9
  • 28
  • This would be done client-side (potentially with jQuery) as you suspect. ASP.NET server-side code can't change browser behavior, so it's mainly a JavaScript/CSS trick you'd be implementing. – David Aug 04 '14 at 15:07
  • Try to use HTML5 attribute `LoginSearch.Attributes.Add("autofocus","autofocus")` in your Page_Load instead of .Focus – Murali Murugesan Aug 04 '14 at 15:12
  • 1
    @Murali My only concern with HTML5 is browser support. This has to work on IE8+ – Brian H Aug 04 '14 at 15:19
  • Check this http://stackoverflow.com/questions/8280988/how-to-make-input-autofocus-in-internet-explorer Just add a line of jQuery code in document.ready to take care of it. – Murali Murugesan Aug 04 '14 at 15:24
  • Better, add `$('[autofocus]').filter(':visible:not(:hidden):focusable:not(:focus)').eq(0).focus();` in your document.ready of jQuery incase if you need a support for IE<10 – Murali Murugesan Aug 04 '14 at 15:26

0 Answers0