473,414 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Selecting all text in a textbox?

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
Nov 17 '05 #1
3 24229
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

"Harry Simpson" <hs*******@nospamphgt.net> wrote in message
news:Ov**************@tk2msftngp13.phx.gbl...
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

Nov 17 '05 #2
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

"Marc Hoeppner" <ma**********@hotmail.com> wrote in message
news:ey**************@TK2MSFTNGP11.phx.gbl...
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

"Harry Simpson" <hs*******@nospamphgt.net> wrote in message
news:Ov**************@tk2msftngp13.phx.gbl...
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


Nov 17 '05 #3
You got it :) - Control.Attributes is kind of hard to find if you don't
already know about it...

"Harry Simpson" <hs*******@nospamphgt.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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

"Marc Hoeppner" <ma**********@hotmail.com> wrote in message
news:ey**************@TK2MSFTNGP11.phx.gbl...
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

"Harry Simpson" <hs*******@nospamphgt.net> wrote in message
news:Ov**************@tk2msftngp13.phx.gbl...
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



Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: DOTNETGUY | last post by:
What i am doing is pretty simple. I am writing a simple control that you probably have seen on many websites. You have a phone number field ( 3 Textboxes ) if the size of the textbox text is = 3...
4
by: melanieab | last post by:
Hi, I need to write something so that when a textbox is entered (this is for a touchscreen), all the text in that textbox is selected (highlighted) and new keystrokes replace the old text. Help!...
3
by: Strange Cat | last post by:
Hi everyone Is it possible to select the contents in an aspnet textbox? (Like the old textbox selectstart and so on properties) Thanx in advance
5
by: marfi95 | last post by:
I'm very confused. I'm trying to automatically select the text when my textbox gets the focus. This is typically when the user has clicked the mouse in the field. This is the code I have in...
4
by: rcoco | last post by:
I want to select one Row from a datagrid so I create a textBbox(txtname) and Button for the user to write the name in textBox and By the click of the button it select the corresponding row. But...
2
by: Abubakar | last post by:
Hi, In a normal Windows.Forms.TextBox control, I want to be able to select a text (ie highlight, this is by default possible) and than be able to drag that text through my mouse pointer to another...
2
by: JJ | last post by:
I have a textbox that is used to insert some html code. I want to highlight errors in the code, possibly by selecting the text. Is it possible to highlight/select areas of a textbox...
1
by: David C | last post by:
I see that the .Focus() method is new in .NET 2.0, which I think is handy. But is there a way to make text in a textbox selected when the focus is set in it? This would be equivalent to calling...
3
by: Shawn | last post by:
I'm trying to go through a large number of logically named textboxes using a loop and cannot figure out how short of explicitly referencing every single one.
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.