如何保持后回后,只读文本框的文本? [英] how to keep the text of a Read only textbox after post-back?

查看:83
本文介绍了如何保持后回后,只读文本框的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET文本框,我希望它是只读。 (使用另一个控制用户修改)

I have an ASP.NET TextBox and I want it to be ReadOnly. (The user modify it using another control)

但是,当有一个回发,文本被重置为空字符串。

But when there is a postback, the text get reset to an empty string.

我明白,如果你设置的只读属性的 true的文本框的内容不打通后救回。

I understand that if you set the readonly property to true of a text box its content does not get saved through post back.

有没有办法让回传后的内容,使文本不能由用户编辑的?

is there a way to keep the content after postback and make the textbox not editable by the user?

我试着在已启用属性设置为,但仍内容不回发后保存

I tried to set the Enabled property to false, but still the content doesn't save after postback

推荐答案

另外soloution我发现,更容易之一:

Another soloution I found and easier one:

这添加到页面加载方法

protected void Page_Load(object sender, EventArgs e)
{
     TextBox1.Attributes.Add("readonly", "readonly");
}

这篇关于如何保持后回后,只读文本框的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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