ASP.NET - Web 服务器控件

<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:Verdana; panose-1:2 11 6 4 3 5 4 4 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:536871559 0 0 0 415 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->

ASP.NET - Web 服务器控件

Web 服务器控件是服务器可理解的特殊 ASP.NET 标签。

类似 HTML 服务器控件,Web 服务器控件也在服务器上创建,它们同样需要 runat="server" 属性以使其生效。不过,Web 服务器控件没有必要映射任何已存在的 HTML 元素,它们代表更复杂的元素。

创建 Web 服务器控件的语法是:

<asp:control_name id="some_id" runat="server" />

在下面的例子中,我们在 .aspx 文件中的声明了一个 Button 服务器控件。然后我们为 Click 事件创建了一个事件句柄,它可修改按钮上的文本:

<script runat="server">

Sub submit(Source As Object, e As EventArgs)

button1.Text="You clicked me!"

End Sub

</script>

 

<html>

<body>

 

<form runat="server">

<asp:Button id="button1" Text="Click me!" runat="server" OnClick="submit"/>

</form>

 

</body>

</html>

ASP.NET - Validation 服务器控件

Validation 服务器控件用于验证用户输入。如果用户输入没有通过验证,将给用户显示一条错误消息。

每种 validation 控件执行一种特定的验证类型(比如验证某个具体的值或者某个范围的值)。

默认地,当点击 Button, ImageButton LinkButton 时,页面验证才会被执行。您可通过把 CausesValidation 属性设置为 false,来阻止某个按钮控件被点击时进行验证。

创建 Validation 服务器控件的语法是:

<asp:control_name id="some_id" runat="server" />

在下面的例子中,我们在 .aspx 文件中声明了一个 TextBox 控件,一个 Button 控件,以及一个 RangeValidator 控件。如果验证失败,文本 "The value must be from 1 to 100!" 将显示在 RangeValidator 控件中:

<html>

<body>

<form runat="server">

 

<p>Enter a number from 1 to 100:

<asp:TextBox id="tbox1" runat="server" />

<br /><br />

<asp:Button Text="Submit" runat="server" />

</p>

 

<p>

<asp:RangeValidator

ControlToValidate="tbox1"

MinimumValue="1"

MaximumValue="100"

Type="Integer"

Text="The value must be from 1 to 100!"

runat="server" />

</p>

 

</form>

</body>

</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值