Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 472
Bex Avatar asked Nov 21 '17 09:11

Bex


3 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!

like image 118
Bex Avatar answered Oct 14 '22 15:10

Bex


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";
like image 38
Abhishek Maurya Avatar answered Oct 14 '22 14:10

Abhishek Maurya


The mainly problem is compatibility issue while you using runat="server" on input field. If you are using dot.net framework below than 4, then you could be getting this problem.

Solution:

Remove runat="server" and call the textbox in server side by using Request.Form("name"). Please do, be the text box as html input instead of using runat="server"

Update for the .NET Framework 4: March, 2011 - enter image description here

and please visit this discussions

Render ASP.NET TextBox as HTML5 Input type "Number"

Details:

Using HTML5 input types in ASP.NET Web Forms

Now comes the main point - How to use the new input types in ASP.NET? Obviously, you can use raw tags as shown above in your web form and then use Request.Form collection to access individual values but if you are developing a web forms based application chances are that you will be using server side controls (either HTML server controls or Web server controls) rather than raw HTML markup. In such cases your textboxes will take either of the following form:

<input id="Text1" type="text" runat="server" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

Now the problem is that VS2010 default installation doesn't take into account the new input types provided by HTML5. As a result you can't use the new input types in your web forms. Luckily, there is an update available on MSDN Download Center that fixes the issue for Web server controls (but not for HTML server controls). If you have this update installed, you can use TextBox server control like this:

<asp:TextBox ID="TextBox1" runat="server" type="date"></asp:TextBox>

Notice the type attribute added to <asp:TextBox> tag. This way you can specify any new HTML5 input type and the resultant control will be rendered accordingly. The way you access TextBox server control on the server remains unchanged.

like image 42
Ramesh Rajendran Avatar answered Oct 14 '22 15:10

Ramesh Rajendran