ASp.net 生成页面,服务器控件对应html标签

本文介绍了 ASP.NET 中使用的服务器控件及其 HTML 对等物。服务器控件可以在服务器端进行访问,并通过 CSS 进行样式设置。文章还提供了一个表格,详细列出了各种服务器控件及其对应的 HTML 元素。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Server controls

Besides HTML elements, ASP.NET uses server controls which have similar definition to HTML elements. The important difference between the two is that, unlike HTML elements, server controls are accessible from the code-behind or: the server side. This is determined with runat="server" attribute in their definitions. Server controls have different attributes than HTML elements and they are called properties. For example, Image control (which is equivalent to IMG element) has ImageUrl property instead of SRC attribute. But Visual Studio has very useful feature called intellisense which is some kind of autocomplete for your code and that will help you explore various properties.

Imoprtan note: Always style elements using CSS insted of server controls properties.

Server controls are much simpler than you might think. Each server control is rendered to a known HTML element on the client. Here is a list of server controls with their HTML equivalents and selectors that can be used from CSS or jQuery.

 

 

Server controlHTML equivalentCSS/jQuery selector
Label <span>span
TextBox<input type="text">input[type="text"]
TextBox (TextMode="Password")<input type="password">
input[type="password"]
TextBox (TextMode="Multiline")<textarea>
textarea
Button<input type="submit">input[type="submit"]
LinkButton<a href="postback options">a
ImageButton<input type="image">input[type="image"]
HyperLink<a>a
DropDownList<select>select
ListBox<select size="n">select
CheckBox<input type="checkbox"> with <label>input[type="checkbox"]
CheckBoxList<table> with a list of <input type="checkbox">table or table input[type="checkbox"] for items
RadioButton<input type="radio"> with <label>input[type="radio"]
RadioButtonList<table> with a list of <input type="radio">table or table input[type="radio"] for items
Image<img>img
ImageMap<img>img
Table<table>table
BulletedList<UL> or <OL> based on BulletedStyle propertyul or ol
HiddenField<input type="hidden">input[type="hidden"]
LiteralLiteral doesn't have its HTML equivalent, it is usually used as a placehoder to render HTML generated on the server 
Calendar<table><table>
FileUpload<input type="file">input[type="file"]

 

 

All server controls are placed in Toolbox positioned on the left side if Visual Studio window. The controls listed in the table above are placed in "standard" panel in the Toolbox. To see how ASP.NET renders controls let's have a look at one example.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值