0

I need to style substring in textbox. I tried, but there is only one way to change color & font to whole value with setting font & foreground color of the control. Here is sample code,

AAAA***AAAB***BBBBB**Baa**aaaaaaBBBBBBBBBA**AAAA**AAAbbbb**bb**b

Or how to load html(contans tags to style the string) in textbox.

Sino Raj
  • 6,431
  • 2
  • 22
  • 23
  • 1
    Try to use the search: [Is it possible to have several different textcolors in one textarea?](http://stackoverflow.com/questions/3435167/is-it-possible-to-have-several-different-textcolors-in-one-textarea). – CodeCaster Mar 15 '14 at 11:11
  • I need dynamically to change text, all values are in textbox(.aspx.cs page). But i want to change color and font to highlight within the .aspx.cs page. @CodeCaster – Sino Raj Mar 15 '14 at 11:26
  • Read the link I gave you. ASP.NET generates HTML, and HTML has no built-in option to set multiple colors in one textbox. – CodeCaster Mar 15 '14 at 11:27
  • Ok,Thanks @CodeCaster. Any other control to solve this problem like html text area or any other. Because I need to solve within the .aspx.cs page, the text result to show in control is from some custom library file's – Sino Raj Mar 15 '14 at 11:34
  • 1
    Again, try to use the search, that question has been answered before. There most likely isn't a ready-made ASP.NET WebForms control that does this, so you'll have to do something with JavaScript and CSS. – CodeCaster Mar 15 '14 at 11:35

1 Answers1

1

good question! There is CSS3 feature based on attribute value selector. But it's not usable to set different font to only part of input control, it's just only selector. See attribute matching selector

I'm affraid you must use some trick like input which will be covered by multiple labels which will display part of input value and each label will have different font.

Jaroslav Kubacek
  • 1,387
  • 18
  • 26
  • I need dynamically to change text, all values are in textbox(.aspx.cs page). But i want to change color and font to highlight within the .aspx.cs page. – Sino Raj Mar 15 '14 at 11:19
  • So I'm afraid you have to write your own ASP.NET Server Controls which will use some trick. Textbox is generated as an input type="text" element and It does not support any similar functionality. – Jaroslav Kubacek Mar 15 '14 at 11:30
  • Any other technique to solve. This is, one of the result of my application. – Sino Raj Mar 15 '14 at 11:37
  • 1
    Another idea but again text will be not formated during editing process: What about a DIV element (with attribute contentEditable = "true") which will contain text. Parts of text will be wrapped by SPAN elements. Each SPAN will have different font according to your needs. Then you need some event (e.g. jquery focusin/focusout) which will fire javascript function like textUpdated which will reformat (rewrape) new text content with SPANs based on regex or other rule or format to single text in case of editing. – Jaroslav Kubacek Mar 15 '14 at 12:01