473,607 Members | 2,659 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8659
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.EventArg s)
TextBox1.Attrib utes.Add("onfoc us", "saveValue(this );")
TextBox1.Attrib utes.Add("onblu r", "getValue(this) ;")
TextBox2.Attrib utes.Add("onfoc us", "saveValue(this );")
TextBox2.Attrib utes.Add("onblu r", "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="javas cript" 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*****@discus sions.microsoft .comescreveu na mensagem
news:CD******** *************** ***********@mic rosoft.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.EventArg s)
TextBox1.Attrib utes.Add("onfoc us", "saveValue(this );")
TextBox1.Attrib utes.Add("onblu r", "getValue(this) ;")
TextBox2.Attrib utes.Add("onfoc us", "saveValue(this );")
TextBox2.Attrib utes.Add("onblu r", "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="javas cript" 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*****@discus sions.microsoft .comescreveu na mensagem
news:CD******** *************** ***********@mic rosoft.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.getIdF romElement("Tex tbox1").select( );
--

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

"Dabbler" <Da*****@discus sions.microsoft .comescreveu na mensagem
news:75******** *************** ***********@mic rosoft.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.EventAr gs)
TextBox1.Attri butes.Add("onfo cus", "saveValue(this );")
TextBox1.Attri butes.Add("onbl ur", "getValue(this) ;")
TextBox2.Attri butes.Add("onfo cus", "saveValue(this );")
TextBox2.Attri butes.Add("onbl ur", "getValue(this) ;")
' for testing propose let's add some text on it
TextBox1.Tex t = "old value 1"
TextBox2.Tex t = "old value 2"
End Sub
and add the really simple javascript function:
<script language="javas cript" 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*****@discus sions.microsoft .comescreveu na mensagem
news:CD******* *************** ************@mi crosoft.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.getIdF romElement("Tex tbox1").select( );
--

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

"Dabbler" <Da*****@discus sions.microsoft .comescreveu na mensagem
news:75******** *************** ***********@mic rosoft.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.EventArg s)
TextBox1.Attrib utes.Add("onfoc us", "saveValue(this );")
TextBox1.Attrib utes.Add("onblu r", "getValue(this) ;")
TextBox2.Attrib utes.Add("onfoc us", "saveValue(this );")
TextBox2.Attrib utes.Add("onblu r", "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="javas cript" 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*****@discus sions.microsoft .comescreveu na mensagem
news:CD******** *************** ***********@mic rosoft.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
4550
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 selected, but then they are somehow unselected as the form posts. Any idea? My Html and ..net code follows: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD>
3
2236
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 = "server='Sistemas'; user id='sa'; password=''; database='Sistemas'" Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString) Dim queryString As String = "SELECT .* FROM WHERE (. = @Usuario)"
2
4334
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 why). txtNote.Text = "the text" txtNote.Enabled = True 'txtNote.Select()
8
21871
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 doesn't seem to work in .net when the textbox receives focus via a mouse click. Jeffrey and Shane both advised how to get a mouse click to select all the text (thank you both) but using the mousedown or mouseup events doesn't work the way I want it...
12
2143
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: Form1 - contains a panel (System.Windows.Forms.Panel)
13
5775
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 CatalogImage where imgID also needs to be placed. Below is my code behind to carry the catID using the Select @@Identity and insert imgID to the bridge table. No data is being entered into the bridge table.
5
1750
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 option of it are: General Support, Technical Support, Sales in billing, Request RA no. and Others. If they select Others there will be a pop-up textbox for others(so they can specify a comment type) and the textbox is placed on a DIV. I placed CSS on...
15
11652
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 "Select" <asp:GridView ID="grdDept" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="DocumentID" DataSourceID="sdsDepartment" Width="600px" CellPadding="4" ForeColor="#333333"...
0
7987
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8464
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6805
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5471
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3954
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4015
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1574
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1318
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.