SollyM SollyM - 2 months ago 9
ASP.NET (C#) Question

How do I force ASP:TextBox to be of type email?

I have an

ASP.NET 3.5
application and I'd like to add the
type="email"
according to
HTML5
standards but if I add the type on the
ASP:TextBox
control I get the below output:

<input name="ctl00$content$txtEmailAddress" type="text" type="email" value=""
id="ctl00_content_txtEmailAddress" class="input-block-level" required="required"/>


How can I replace the type attribute from "text" to "email"?

Answer

If you using .Net 3.5 then no matter what type you have specified with <asp:TextBox>, it will always render with <input type="text" />. So in that case you can use simple html input with type="email"

<input type="email" />

For 4.5 version you can use TextMode="Email"

<asp:TextBox ID="txtmyBox" runat="server" TextMode="Email"></asp:TextBox>