当前位置:网站首页>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样式如下:
边栏推荐
- Industry insight | is speech recognition really beyond human ears?
- GAMES101复习:光线追踪(Ray Tracing)
- Web服务器
- What "posture" does JD cloud have to promote industrial digitalization to climb to a "new level"?
- Original title of Blue Bridge Cup
- Embedded sharing collection 22
- 阿憨的故事
- @The function of valid (cascade verification) and the explanation of common constraint annotations
- 【stream】并行流与顺序流
- els 键盘信息
猜你喜欢

嵌入式分享合集22

Is it you who are not suitable for learning programming?

Why is it that when logging in, you clearly use the account information already in the database, but still display "user does not exist"?

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

一次跨域问题的记录

ROS的调试经验

为什么登录时,明明使用的是数据库里已经有的账号信息,但依旧显示“用户不存在”?

JVM 内存布局详解,图文并茂,写得太好了!

TFX airflow experience

Building of APP automation environment (I)
随机推荐
Design and practice of unified security authentication for microservice architecture
style=“width: ___“ VS width=“___“
Docker advanced -redis cluster configuration in docker container
els 显示一个随机方块
Distributed transaction Senta (I)
Original title of Blue Bridge Cup
分布式事务——Senta(一)
[email protected]注解使用
Actual case of ROS communication
阿憨的故事
stm32F407-------FPU学习
【红队】ATT&CK - 文件隐藏
Data center construction (III): introduction to data center architecture
The applet has obtained the total records and user locations in the database collection. How to use aggregate.geonear to arrange the longitude and latitude from near to far?
方案分享 | 高手云集 共同探索重口音AI语音识别
树莓派开发继电器控制灯
基于JSP&Servlet实现的众筹平台系统
CNN循环训练的解释 | PyTorch系列(二十二)
智能工业设计软件公司天洑C轮数亿元融资
Where do I go to open an account for stock speculation? Is it safe to open an account on my mobile phone