I have a custom TextBox control designed for accepting currency values. I call it the CurrencyTextBox. It renders as <input type="text" .../> but the issue is I need it to render <input type="currency" .../>. Note - In case you're wondering, "currency" is not a standard type, it is a custom type.
Here's a sample of some code. It all works fine apart from this one issue.
public class CurrencyTextBox : TextBox
{
protected override void OnPreRender(EventArgs e)
{
//I have some code in here to render client side scripts
}
protected override void Render(HtmlTextWriter writer)
{
writer.AddAttribute("onfocus", "__ctbFocus(this);");
writer.AddAttribute("onkeydown", "return __ctbKeyDown(this);");
writer.AddAttribute("onkeypress", "return __ctbKeyPress(this);");
writer.AddAttribute("onchange", "return __ctbChange(this)");
//I have more code here which adds several more attributes
base.Render(writer);
}
}
I'm struggling to work out how to change the "type" attribute from the rendered markup. I want to change text="type" to say text="currency". It's easy enough just to add the attribute, as in
writer.AddAttribute("text", "currency")
but it still renders ' type="text" '. So I tried the following
Attributes.Remove("type");
but that doesn't work, it just doesn't do anything.
Perhaps I need to use
protected override void RenderAttributes(HtmlTextWriter writer)
but I can't work out exactly what the code should be or where it should go.