473,385 Members | 1,772 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,385 software developers and data experts.

select text in TextBox from code?

Is there a way to mark the text in a TextBox control as selected so when the
user types a new value the existing text is replaced?

Thanks
Aug 18 '06 #1
4 8653
just using javascript and add the event OnFocus on the textbox

you can implement in many ways:

when the user focus the textbox you delete all the value and present it as
new textbox
or when the user focus the textbox you delete all and if the user did not
changed the value you paste the old value back in the textbox
imagine that you have 2 textboxs called TextBox1 and TextBox2

onPageLoad add the onfous and onblur event to the textbox like:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
TextBox1.Attributes.Add("onfocus", "saveValue(this);")
TextBox1.Attributes.Add("onblur", "getValue(this);")
TextBox2.Attributes.Add("onfocus", "saveValue(this);")
TextBox2.Attributes.Add("onblur", "getValue(this);")
' for testing propose let's add some text on it
TextBox1.Text = "old value 1"
TextBox2.Text = "old value 2"
End Sub
and add the really simple javascript function:
<script language="javascript" type="text/javascript">
var oldValue = ''; // it will save our old values

function getValue( v ) {
if(v.value == '')
v.value = oldValue;
}
function saveValue( v ) {
oldValue = v.value;
v.value = '';
}
</script>
hope it helps

--

Bruno Alexandre
"a Portuguese in Københav, Danmark"

"Dabbler" <Da*****@discussions.microsoft.comescreveu na mensagem
news:CD**********************************@microsof t.com...
Is there a way to mark the text in a TextBox control as selected so when
the
user types a new value the existing text is replaced?

Thanks

Aug 18 '06 #2
Hi Bruno

Well, I'm setting focus from code behind already. Would just like to
highlight the existing text and let user choose to leave it or delete it by
typing a new value. Is it possible to trigger Ctrl-A from javascript which
would select everything in the TextBox?

Thanks.

"Bruno Alexandre" wrote:
just using javascript and add the event OnFocus on the textbox

you can implement in many ways:

when the user focus the textbox you delete all the value and present it as
new textbox
or when the user focus the textbox you delete all and if the user did not
changed the value you paste the old value back in the textbox
imagine that you have 2 textboxs called TextBox1 and TextBox2

onPageLoad add the onfous and onblur event to the textbox like:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
TextBox1.Attributes.Add("onfocus", "saveValue(this);")
TextBox1.Attributes.Add("onblur", "getValue(this);")
TextBox2.Attributes.Add("onfocus", "saveValue(this);")
TextBox2.Attributes.Add("onblur", "getValue(this);")
' for testing propose let's add some text on it
TextBox1.Text = "old value 1"
TextBox2.Text = "old value 2"
End Sub
and add the really simple javascript function:
<script language="javascript" type="text/javascript">
var oldValue = ''; // it will save our old values

function getValue( v ) {
if(v.value == '')
v.value = oldValue;
}
function saveValue( v ) {
oldValue = v.value;
v.value = '';
}
</script>
hope it helps

--

Bruno Alexandre
"a Portuguese in Københav, Danmark"

"Dabbler" <Da*****@discussions.microsoft.comescreveu na mensagem
news:CD**********************************@microsof t.com...
Is there a way to mark the text in a TextBox control as selected so when
the
user types a new value the existing text is replaced?

Thanks


Aug 18 '06 #3
for that you use javascript

document.getIdFromElement("Textbox1").select();
--

Bruno Alexandre
"a Portuguese in Københav, Danmark"

"Dabbler" <Da*****@discussions.microsoft.comescreveu na mensagem
news:75**********************************@microsof t.com...
Hi Bruno

Well, I'm setting focus from code behind already. Would just like to
highlight the existing text and let user choose to leave it or delete it
by
typing a new value. Is it possible to trigger Ctrl-A from javascript which
would select everything in the TextBox?

Thanks.

"Bruno Alexandre" wrote:
>just using javascript and add the event OnFocus on the textbox

you can implement in many ways:

when the user focus the textbox you delete all the value and present it
as
new textbox
or when the user focus the textbox you delete all and if the user did not
changed the value you paste the old value back in the textbox
imagine that you have 2 textboxs called TextBox1 and TextBox2

onPageLoad add the onfous and onblur event to the textbox like:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
TextBox1.Attributes.Add("onfocus", "saveValue(this);")
TextBox1.Attributes.Add("onblur", "getValue(this);")
TextBox2.Attributes.Add("onfocus", "saveValue(this);")
TextBox2.Attributes.Add("onblur", "getValue(this);")
' for testing propose let's add some text on it
TextBox1.Text = "old value 1"
TextBox2.Text = "old value 2"
End Sub
and add the really simple javascript function:
<script language="javascript" type="text/javascript">
var oldValue = ''; // it will save our old values

function getValue( v ) {
if(v.value == '')
v.value = oldValue;
}
function saveValue( v ) {
oldValue = v.value;
v.value = '';
}
</script>
hope it helps

--

Bruno Alexandre
"a Portuguese in Københav, Danmark"

"Dabbler" <Da*****@discussions.microsoft.comescreveu na mensagem
news:CD**********************************@microso ft.com...
Is there a way to mark the text in a TextBox control as selected so
when
the
user types a new value the existing text is replaced?

Thanks



Aug 18 '06 #4
Thanks for the tip Bruno,

sorry, I'm still new at js from ASP.NET, how would I call this from
codebehind in pageload?

Thanks.


"Bruno Alexandre" wrote:
for that you use javascript

document.getIdFromElement("Textbox1").select();
--

Bruno Alexandre
"a Portuguese in Københav, Danmark"

"Dabbler" <Da*****@discussions.microsoft.comescreveu na mensagem
news:75**********************************@microsof t.com...
Hi Bruno

Well, I'm setting focus from code behind already. Would just like to
highlight the existing text and let user choose to leave it or delete it
by
typing a new value. Is it possible to trigger Ctrl-A from javascript which
would select everything in the TextBox?

Thanks.

"Bruno Alexandre" wrote:
just using javascript and add the event OnFocus on the textbox

you can implement in many ways:

when the user focus the textbox you delete all the value and present it
as
new textbox
or when the user focus the textbox you delete all and if the user did not
changed the value you paste the old value back in the textbox
imagine that you have 2 textboxs called TextBox1 and TextBox2

onPageLoad add the onfous and onblur event to the textbox like:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
TextBox1.Attributes.Add("onfocus", "saveValue(this);")
TextBox1.Attributes.Add("onblur", "getValue(this);")
TextBox2.Attributes.Add("onfocus", "saveValue(this);")
TextBox2.Attributes.Add("onblur", "getValue(this);")
' for testing propose let's add some text on it
TextBox1.Text = "old value 1"
TextBox2.Text = "old value 2"
End Sub
and add the really simple javascript function:
<script language="javascript" type="text/javascript">
var oldValue = ''; // it will save our old values

function getValue( v ) {
if(v.value == '')
v.value = oldValue;
}
function saveValue( v ) {
oldValue = v.value;
v.value = '';
}
</script>
hope it helps

--

Bruno Alexandre
"a Portuguese in Københav, Danmark"

"Dabbler" <Da*****@discussions.microsoft.comescreveu na mensagem
news:CD**********************************@microsof t.com...
Is there a way to mark the text in a TextBox control as selected so
when
the
user types a new value the existing text is replaced?

Thanks


Aug 18 '06 #5

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

Similar topics

2
by: Mad Scientist Jr | last post by:
I'm trying to get javascipt select all items in a HTML form <SELECT> control and submit the form to an asp.net page. For some reason when the link is clicked, you can see the items all get...
3
by: Ruben | last post by:
I have this code, I need see in textbox.text all my information, how I do that Function Consultas(ByVal usuario As String) As System.Data.DataSet Dim connectionString As String =...
2
by: Cindy M -WordMVP- | last post by:
Hi all While working my way through a VB.NET exercise, I came across something that didn't do what the text said it should and I'm wondering if it's supposed to behave this way, or not (and...
8
by: cj | last post by:
I asked this question a couple of days ago but am just now looking at it again. I used to use the textbox gotfoucs event to have all the text in the textbox selected when it gotfocus. That...
12
by: Brano | last post by:
Hi I am using vb.net 2005 this is a windows application I am using this functionality in another project I have created this simple project to show the problem Basically I have two forms: ...
13
by: PinkBishop | last post by:
I am using VS 2005 with a formview control trying to insert a record to my access db. The data is submitted to the main table no problem, but I need to carry the catID to the bridge table...
5
tjc0ol
by: tjc0ol | last post by:
Hi all, I made contact page which allows visitors to input their name, email address, phone number, comments and select a comment type by using <select> element in html with javascript. Among the...
15
JustRun
by: JustRun | last post by:
I have a problem with the select option at the gridview and gonna pull my hair out cause it doesn't work at all. Here is the Grid view code: I want to get the selected row when the user click...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.