How do I force ASP:TextBox to be of type email?
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>
Sorry I'm a bit late to the party, though I think that others can benefit from what I did. I have a page which is HTML 5 though we still have .NET 3.5. We wanted to keep the .NET element, though have the type change to email.
I've tried several methods, though the one which worked for me was the following: I added a JavaScript property to the element itself inline (when I put it in a script tag it wouldn't pick up for some reason...)
Here is what your tag would look like if you use my changes:
<asp:TextBox runat="server" type="email" onfocus="this.type='email'"/>