Render ASP.NET TextBox as HTML5 Input type “Number”

后端 未结 7 1157
暗喜
暗喜 2020-11-30 12:16

When an ASP.NET TextBox renders it produces:


However I need it to render as a HTML5 number type instead, like

7条回答
  •  广开言路
    2020-11-30 12:46

    Override the base textbox control

    public class HTML5TextBox : TextBox
    {
    .....
    protected override void Render(HtmlTextWriter writer)
    {
    //Sth like the code below, you need do some research though
     writer.AddAttribute(HtmlTextWriterAttribute.Type,"Number");
     writer.AddAttribute(HtmlTextWriterAttribute.Id, ClientID + "_displayTXT");
     writer.AddAttribute(HtmlTextWriterAttribute.Name,this.UniqueID + "t1");
     writer.AddAttribute(HtmlTextWriterAttribute.Value,base.Text);
     writer.RenderBeginTag(HtmlTextWriterTag.Input);       
     writer.RenderEndTag(); 
    }
    ....
    }
    

    Or you can check the one I just found at http://www.codeproject.com/Articles/68834/Enhanced-Textbox-Control

提交回复
热议问题