为什么只读文本框在 ASP.NET 中不返回任何数据? [英] Why does a read-only textbox not return any data in ASP.NET?

查看:13
本文介绍了为什么只读文本框在 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 中不返回任何数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆