changing color of a string inside an asp.net textbox

Discussion in 'ASP .Net' started by jc, Jun 18, 2008.

  1. jc

    jc Guest

    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!
     
    jc, Jun 18, 2008
    #1
    1. Advertising

  2. jc

    bruce barker Guest

    <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!
    >
     
    bruce barker, Jun 19, 2008
    #2
    1. Advertising

  3. jc

    nick chan Guest

    document.getElementById('textboxclientid').style.color = 'Blue';



    On Jun 19, 6:24 am, 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!
     
    nick chan, Jun 19, 2008
    #3
  4. jc

    jc Guest

    > 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').createTextRange().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.
     
    jc, Jun 19, 2008
    #4
  5. jc

    jc Guest

    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').createTextRange().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').createTextRange().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').createTextRange().find(selectit);
     
    jc, Jun 19, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. moondaddy
    Replies:
    3
    Views:
    38,971
    moondaddy
    Apr 28, 2004
  2. =?Utf-8?B?TWFoZXI=?=

    TextBox Changing Color

    =?Utf-8?B?TWFoZXI=?=, Apr 27, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    457
    James Doughty
    Apr 27, 2005
  3. PJ6
    Replies:
    4
    Views:
    4,927
  4. Kamaljeet Saini
    Replies:
    0
    Views:
    494
    Kamaljeet Saini
    Feb 13, 2009
  5. mr_burns

    Changing textbox background color

    mr_burns, Nov 26, 2004, in forum: Javascript
    Replies:
    2
    Views:
    194
    Daniel Kirsch
    Nov 26, 2004
Loading...

Share This Page