'number' is not a valid type for an input tag - On my local machine only

Viewed 7398

I am trying to work on an already live Asp.Net/Web Forms project.

It all compiles fine in visual studio but when I run a particular page under my local IIS I get

'number' is not a valid type for an input tag.

on this line of html:

<input type="number" ID="txtNum" runat="server" class="txt" step='0.01'
   value='0.00' placeholder='0.00' min="0" />

There are a lot of people complaining of the same problem but the only solutions I am seeing is to update the code or HTML which is something I can't do as this works on the live server and on another developers machine.

UPDATE (based on suggested duplicate)

I have already looked at this question:

How can I use HTML5 email input type with server-side .NET

It suggests installing an update to .net 4 http://support.microsoft.com/kb/2468871. I think this machine was installed after 2011 anyway but either way the updates wont install it says:

KB2468871v2 does not apply, or is blocked by another condition on your computer.

I dont know if this means the updates already installed or not??

The other answers suggest code/html changes which I am unable to do as this is already working elsewhere.

What am I missing on my machine?

8 Answers

This makes no sense.. but as inspired by this answer: https://stackoverflow.com/a/27561096/390501

I updated my Target Framework in Visual Studio to 4.5.1 rather than 4.5 and now the page loads without a parser error!

Use this code to use HTML5 input type:

Use this in .aspx file:

<input type="text" placeholder='0.00' ID="txtNum" runat="server" class="txt/>

Use this in .cs file:

 txtNum.Attributes["type"] = "number";
 txtNum.Attributes["value"] = "0.00";
 txtNum.Attributes["min"] = "0";
 txtNum.Attributes["step"] = "0.01";

Check if your browser supports HTML5 or not. If it supports and still not showing then explicitly tell the browser that you are using html5 tags.

Use this in your .aspx file.

<!DOCTYPE html> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

This issue happening because .net framework installed in your machine does not have System.Web.UI.HtmlControls.HtmlInputGenericControl class.

This class defines the methods, properties, and events for server-side access to the HTML5 input element. (Reference - MSDN)

It is available since .Net 4.5.

Steps to solve the problem

1. make sure .Net 4.5 framework is available in the server machine.

2. make sure the target framework for the projects in your solution are pointing to .Net 4.5

3. Make sure the website is using 4.0 app pool in IIS.

Check prerequisites for this update
- To apply this update, you must have the .NET Framework 4 or the .NET Framework 4 Client Profile installed.
- To install this update, you must have Windows Installer 3.1 or a later version installed. To obtain the latest version of Windows Installer, visit the following Microsoft website

if your machine already have the prerequisites
- Running a visual studio product repair from the Programs and features, located on windows control panel.
- Rerun the patch, hotfix.

Installing HTML 5 Updates for .NET 4 from Reliability Update 1 for the .NET should enable .net framework to understand html5 controls.

Quoting msdn;

The first update was shipped with VS 2010 SP1. You can read about the framework update here: http://support.microsoft.com/kb/2468871. One of the features of HTML 5 is there are now new input types such as date, url, email and more. While most browsers today don’t support these new input types you should still use them today because most mobile devices do support them and it changes the keyboard these devices display. For example specifying type=”email” will cause many phones to provide the “@” character on the keyboard. type=”email” or type=”url” will cause many phones to provide the “.com” button on the keyboard as a shortcut.

Before the update above it was illegal to use these input types in Web Forms. The following would generate an error:

<asp:TextBox id=”TextBoxEmail” runat=”server” type=”email” />

Because we were validating what values could be provided for the type= attribute. This validation was relaxed as part of the above update.

In vb.net

In .aspx page :

<input id="txtNum" runat="server"/>

In .vb page, in PageLoad():

txtNum.Attributes.Add("type","number")

type="number" in html inputs may produce parser error

Related