Why does a read-only textbox not return any data in ASP.NET?(为什么只读文本框在 ASP.NET 中不返回任何数据?)
问题描述
我已将文本框设置为只读.当用户点击它时,会显示一个日历,并且用户选择输入到只读文本框中的日期.
I've set a textbox to read-only. When the user clicks on it, a calendar is displayed and the user selects the date which inputs into the read-only textbox.
但是当我尝试将数据输入数据库时,它显示空值.怎么了?
But when I try to enter the data into the database, it shows null value. What is wrong?
推荐答案
说到 ASP.NET Readonly 属性和 readonly HTML 输入元素的属性.与其设置 Web 控件的 Readonly 属性,不如尝试简单地将 HTML 属性添加到控件,如下所示:
There is a little bit of strangeness when it comes to the ASP.NET Readonly property and the readonly attribute of an HTML input element. Rather than setting the Readonly property of the web control try simply adding the HTML attribute to the control like this:
textBox.Attributes.Add("readonly", "readonly");
这将使控件在客户端浏览器中为只读,但仍允许您在输入回传到服务器时检索输入的值.
This will make the control read-only in the client's browser yet still allow you to retrieve the value of the input when it posts back to the server.
这篇关于为什么只读文本框在 ASP.NET 中不返回任何数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么只读文本框在 ASP.NET 中不返回任何数据?
基础教程推荐
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
