novice_andrei
June 15th, 2009, 08:05 PM
Hi, I've been struggling all night with trying to find a solution for the following problem:
I want to make a custom textbox control that applies css style to certain words. For example if in the textbox the word "class" appears it must be coloured blue.
What I've done so far is this:
namespace Codebox
{
public class Codebox : System.Web.UI.WebControls.TextBox
{
public Codebox()
{
}
protected override void AddAttributesToRender( System.Web.UI.HtmlTextWriter writer )
{
writer.AddStyleAttribute(HtmlTextWriterStyle.FontFamily, "Courier");
writer.AddStyleAttribute(HtmlTextWriterStyle.FontSize, "0.8em");
FormatKeyWords(writer);
base.AddAttributesToRender(writer);
}
private void FormatKeyWords( System.Web.UI.HtmlTextWriter writer )
{
if(this.Text.Contains("class"))
writer.AddStyleAttribute(HtmlTextWriterStyle.Color, "#ff541f");
}
}
}
So the above applies font styling to the whole text in the textbox. But I need to style only specific words - how could I retrieve specific text in the textbox? I assume I need to read the text line by line somehow.
Thanks for any idea
Regards,
I want to make a custom textbox control that applies css style to certain words. For example if in the textbox the word "class" appears it must be coloured blue.
What I've done so far is this:
namespace Codebox
{
public class Codebox : System.Web.UI.WebControls.TextBox
{
public Codebox()
{
}
protected override void AddAttributesToRender( System.Web.UI.HtmlTextWriter writer )
{
writer.AddStyleAttribute(HtmlTextWriterStyle.FontFamily, "Courier");
writer.AddStyleAttribute(HtmlTextWriterStyle.FontSize, "0.8em");
FormatKeyWords(writer);
base.AddAttributesToRender(writer);
}
private void FormatKeyWords( System.Web.UI.HtmlTextWriter writer )
{
if(this.Text.Contains("class"))
writer.AddStyleAttribute(HtmlTextWriterStyle.Color, "#ff541f");
}
}
}
So the above applies font styling to the whole text in the textbox. But I need to style only specific words - how could I retrieve specific text in the textbox? I assume I need to read the text line by line somehow.
Thanks for any idea
Regards,