Render ASP.NET TextBox as HTML5 Input type quot;Numberquot;(将 ASP.NET 文本框呈现为 HTML5 输入类型“数字)
问题描述
当 ASP.NET 文本框呈现时,它会生成:
When an ASP.NET TextBox renders it produces:
<input type="text" />
但是我需要将其呈现为 HTML5 数字类型,例如:
However I need it to render as a HTML5 number type instead, like:
<input type="number" />
这可能吗?
推荐答案
我对使用 ASP.NET 的移动网站有同样的要求.在没有找到好的解决方案后,我尝试直接在文本框上设置 type="number" .令我惊讶的是,它奏效了!难以置信,我创建了一个简单的测试项目来仔细检查.我在每个 .NET 版本中运行了这行代码:
I had the same requirement for a mobile website using ASP.NET. After finding no good solution, I tried simply setting type="number" directly on the textbox. To my surprise, it worked! Incredulous, I created a simple test project to double-check. I ran this line of code in each .NET version:
<!-- this HTML tested in each .NET version -->
<asp:TextBox runat="server" type="number" />
结果如下:
<!-- ASP.NET 2.0, 3.0, and 3.5 -->
<input name="ctl01" type="text" type="number" />
<!-- ASP.NET 4.0 and 4.5 -->
<input name="ctl01" type="number" />
底线:如果您使用的是 ASP.NET 4.0 或更高版本,只需将 type="number" 添加到您的文本框.
Bottom line: if you are using ASP.NET 4.0 or newer, just add type="number" to your textbox.
这篇关于将 ASP.NET 文本框呈现为 HTML5 输入类型“数字"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将 ASP.NET 文本框呈现为 HTML5 输入类型“数字"
基础教程推荐
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- WPF 模态进度窗口 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
