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 中不返回任何数据?


基础教程推荐
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- MS Visual Studio .NET 的替代品 2022-01-01