Selecting all text in a textbox?

  • Thread starter Thread starter Harry Simpson
  • Start date Start date
H

Harry Simpson

I've got a server-side textbox that receives the focus when the page loads.
It has the text "Refine your Search" in the textbox. Obviously the user
needs to highlight the "Refine your Search" section to replace this with
thier text.

I've googled and found javascript (which doesn't seem to work with the
server side control).

Is there a way to do this with ASPNET??

TIA
Harry
 
Hi,

you should be able to use JScript with ASP.NET just fine, in fact you need
JScript to do what you want. What was the problem with the Jscript in
combination with ASP.NET?

Best regards,

Marc Höppner
NeoGeo
 
Thanks Marc,

I got it working:

Added this to the codebehind load of screen:
txtSearchText.Attributes.Add("onfocus", "SetSelected();")

Then add this to the html of the aspx page:

function SetSelected()
{
document.Form1.txtSearchText.select();
}

Thanks for the reply
Harry
 
You got it :) - Control.Attributes is kind of hard to find if you don't
already know about it...
 
Back
Top