当前位置:网站首页>C#设置Textbox控件不可编辑
C#设置Textbox控件不可编辑
2022-07-28 02:22:00 【黄昏和星空】
前言
一般而言,Textbox中有两个属性可以对其进行防止编辑的设定,这是最基础的知识,也是我要提出的前两种方法。而后两种方法实际为一种,但可以应用于不同环境中。
一、ReadOnly属性
这样设置,Textbox控件则限制不能输入,但可以读取已有文本,样式也与正常使用的Textbox一致。
1、在前端设置Readonly为true,样式如下:
<asp:TextBox ID=“TextBox1” runat=“server” ReadOnly=“true” Text=“测试”></asp:TextBox>
2、在后台设置Readonly为true,样式如下:
TextBox1.ReadOnly = true;
二、Enabled属性
设置此属性会将Textbox控件变成反灰样式,不可点击。
1、在前端设置Enabled为false,样式如下:
<asp:TextBox ID=“TextBox1” runat=“server” Enabled=“false” Text=“测试”></asp:TextBox>
2、在后台设置Readonly为true,样式如下:
TextBox1.Enabled= false;
三、onfocus方法
设置JS的事件,onfocus事件指的的是光标移到到此控件,this.blur()是将光标移开,如此便能够达到不能编辑的目的,代码如下。
<asp:TextBox ID=“TextBox1” runat=“server” Text=“测试” οnfοcus=“this.blur();”></asp:TextBox>
四、设置TextModel样式
使用CSS代码,设置TextModel属性。与第三项结合,这样设置的好处是在一些浏览器中同样能实现不能编辑的目的,但是能够保证原有的"X"号存在,所以还可以实现清楚控件内容的目的。经检测,在IE浏览器不支持此功能,但Google浏览器可以。
前端代码如下:
<asp:TextBox ID=“TextBox1” runat=“server” Text=“测试” TextModel=“search” οnfοcus=“this.blur();”></asp:TextBox>
Css样式如下:
边栏推荐
- Skills in writing English IEEE papers
- QT专题1:实现一个简易计算器
- CSDN Top1 "how does a Virgo procedural ape" become a blogger with millions of fans through writing?
- Web server
- Day 19 of leetcode
- JS event object offsetx/y clientx y pagex y
- 42.js -- precompiled
- Qt官方示例:Fridge Magnets Example(冰箱贴)
- Original title of Blue Bridge Cup
- 数据湖:各模块组件
猜你喜欢

意外收获史诗级分布式资源,从基础到进阶都干货满满,大佬就是强!

四、固态硬盘存储技术的分析(论文)

行业洞察 | 语音识别真的超过人耳朵了吗?

exness:日本物价上涨收入下降,英镑/日元突破 165

Opengauss Developer Day 2022 sincerely invites you to visit the "database kernel SQL Engine sub forum" of Yunhe enmo

树莓派开发继电器控制灯

【stream】并行流与顺序流

Qt官方示例:Fridge Magnets Example(冰箱贴)

JS 事件对象2 e.charcode字符码 e.keyCode键码 盒子上下左右移动

Why is it that when logging in, you clearly use the account information already in the database, but still display "user does not exist"?
随机推荐
Distributed transaction Senta (I)
Niuke-top101-bm340
Qt官方示例:Fridge Magnets Example(冰箱贴)
stm32F407-------FPU学习
Stop paging with offset and limit. The performance is too poor!
Data Lake: flume, a massive log collection engine
注意,这些地区不能参加7月NPDP考试
Opengauss Developer Day 2022 sincerely invites you to visit the "database kernel SQL Engine sub forum" of Yunhe enmo
小程序已获取数据库合集中的总记录、用户位置,怎么用Aggregate.geoNear将经纬度由近到远排列?
Embedded sharing collection 22
从硬件编程到软件平台的ci/cd
蓝桥杯原题
Using pytorch's tensorboard visual deep learning indicators | pytorch series (25)
MySQL索引学习
[stream] parallel stream and sequential stream
Web服务器
Where do I go to open an account for stock speculation? Is it safe to open an account on my mobile phone
Superparameter adjustment and experiment - training depth neural network | pytorch series (26)
嵌入式分享合集22
MySQL essay