472,988 Members | 3,278 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

changing color of a string inside an asp.net textbox

jc
It would appear I cannot do this unless it's a richtextbox...

but is there any way I can change the color of a given string inside a
textbox control?

Maybe with javascript? Postrender? CSS?

If not, does anybody have any javascript code where I can atleast
select (hilite) the given text?

Thanks for any help or information!
Jun 27 '08 #1
5 2060
<input type="text"does not support css on text segments (as there is no
span, etc). to set select its just javascript:

document.getElementById('myinput').createTextRange ().find('text to select');
-- bruce (sqlwork.com)
"jc" wrote:
It would appear I cannot do this unless it's a richtextbox...

but is there any way I can change the color of a given string inside a
textbox control?

Maybe with javascript? Postrender? CSS?

If not, does anybody have any javascript code where I can atleast
select (hilite) the given text?

Thanks for any help or information!
Jun 27 '08 #2
document.getElementById('textboxclientid').style.c olor = 'Blue';

On Jun 19, 6:24*am, jc <wild...@noclient.netwrote:
It would appear I cannot do this unless it's a richtextbox...

but is there any way I can change the color of a given string inside a
textbox control?

Maybe with javascript? Postrender? CSS?

If not, does anybody have any javascript code where I can atleast
select (hilite) the given text?

Thanks for any help or information!
Jun 27 '08 #3
"nick chan" <zz*******@gmail.comwrote in message
news:ff**********************************@a9g2000p rl.googlegroups.com...

[top-posting corrected]
>It would appear I cannot do this unless it's a richtextbox...

But is there any way I can change the color of a given string inside a
TextBox control?

document.getElementById('textboxclientid').style.c olor = 'Blue';
That will turn the *entire contents* of the TextBox blue...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #4
jc
document.getElementById('myinput').createTextRange ().find('text to select');
Thank you . I'm trying the below and getting OBJECT EXPECTED error in
javascript.

on my aspx page I have this:

<script language="javascript" type="text/javascript">
function SearchText(selectit)
{
document.getElementById('TextBox_Body').createText Range().find(selectit);
}
</script>

In a class called pkb I have this function:

Public Function SelectText(ByVal SearchString As String) As String
Return "<script language='JavaScript'>" + vbCrLf +
"SearchText('" + SearchString + "')" + vbCrLf + "</script>"
End Function
and attempting to call the javascript like this:
ClientScript.RegisterClientScriptBlock(Me.GetType, "client",
pkb.SelectText(TextBox_Search1.Text))
If rightclick view source on the page and do see that the textboxes ID
is TextBox_Body

If I step through the code, the dynamic javascript looks like this
when passed the string car:

<script language='JavaScript'>
SearchText('car')
</script>
Also, once I get past this, will i be able to select more than one
string or repeating strings? Also how can I make this not care about
case?

Thanks for any help or information.


Jun 27 '08 #5
jc
this gives me error "Object Expected"
The original html source:

<html>
<head>
<title>
Javascript testing
</title>
</head>

<body>

<form name="form1" method="post" action="_Blank" id="form1">
<script language="javaScript" type="text/javascript">
SearchText("test");
</script>
<input name="TextBox_Body" type="text" value="this is a test"
id="TextBox_Body" />
</form>
<script language="javascript" type="text/javascript">
function SearchText(selectit)
{
document.getElementById('TextBox_Body').createText Range().find(selectit);
}
</script>
</body>
</html>

... a view source when the error occurs

<html>
<head>
<title>
Javascript testing
</title>
</head>

<body>

<form name="form1" method="post" action="_Blank" id="form1">
<input name="TextBox_Body" type="text" value="this is a test"
id="TextBox_Body" />
</form>
<script language="javascript" type="text/javascript">
function SearchText(selectit)
{
document.getElementById('TextBox_Body').createText Range().find(selectit);
}
</script>

<script language="javaScript" type="text/javascript">
SearchText("test");
</script>

</body>
</html>
giving me the object expected on line 20

document.getElementById('TextBox_Body').createText Range().find(selectit);
Jun 27 '08 #6

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

Similar topics

2
by: aaj | last post by:
Hi all I have a small but rather annoying problem with continuos forms, and am wondering if anyone can suggest a method of getting over it. The front end is Access 2002 with the BE being SQL...
10
by: Marizel | last post by:
I'm not sure there's an easy solution to this, but thought I'd ask. I often find myself with a query which I'd like to reuse, but with a different datasource. These datasources generally have...
4
by: Tony W | last post by:
Hi, I am trying to write a simple application to retrieve data from the Windows registry and insert it into textboxs on a windows form. So far I have one namespace containing two classess. ...
5
by: Ioannis Vranos | last post by:
When we assign a managed or unmanaged string literal to a String *, is a new String created implicitly in the managed heap? Or in other words, what happens when we assign a string literal to...
7
by: Ed West | last post by:
Hello, I have a simple form with some input boxes. After validation if one fails, then I would like to at the top of the page say something like "The following fields in red are required" and...
0
by: Luis Esteban Valencia | last post by:
Hello. I have a datagrid with one row. I have a button that adds a new row. I am trying to implement that when the user selects one product it must change the price on the quantity column. Anyway...
3
by: Pavan | last post by:
Hi All, I am having a wierd problem while displaying my panel. My code is something like this <table> <tr> <td width=100>label</td> <td width=100>label</td> <td width=100>label</td> <td...
3
by: fbergroth | last post by:
Hi, I'm quite new to C# allthough I've been programming in other languages for quite a while. I'd like to change the blinking cursor inside a TextBox, I guess I must derive the class and...
1
by: dantz | last post by:
Hi everyone, I have a textbox which is multiline and wordwrap is true. I did not set any scrollbar because I want to show it manually (using different buttons) The textbox will sometimes have...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.