asp.net常用基本控件总结

Label控件

功能说明:用于显示文本,提示信息,如窗体标题,文本框的标题

命名前缀:Lbl

ASPX代码:<asp:Label ID=”LblSample” runat=”server” Text=”Label Sample”></asp:Label>

重要属性:Text          显示的文本

 

HyperLink控件

功能说明:建立文本超链接或图片超链接

命名前缀:Hlk

ASPX代码:<asp:HyperLink ID=”HlkSample” runat=”server” NavigateUrl=”www.sample.com.cn”>Sample</asp:HyperLink>

重要属性:NavigateUrl   链接URL

ImageUrl      显示的图片URL

Target        目标框架的名称,如”_blank”,”_top”等

 

Image控件

功能说明:用于显示图片

命名前缀:Img

ASPX代码:<asp:Image ID=”ImgSample” runat=”server” ImageUrl=”build.ImgSample”  />

重要属性:ImageUrl      显示的图片URL

 

Button控件

功能说明:用于创建按钮,执行命令

命名前缀:Btn

ASPX代码:<asp:Button ID=”BtnSample” runat=”server” Text=”Sample” />

重要属性:Text          显示在按钮上的文本

 

TextBox控件

功能说明:用于显示文本和接收用户输入的文本

命名前缀:Txt

ASPX代码:<asp:TextBox ID=”TxtSample” runat=”server” Text=”TextBox Sample”></asp:TextBox>

重要属性:Text          显示在按钮上的文本

TextMode      设置文本的模式,”Single”为单行文本框,”Multiline”为多行文本框

Rows          当TextMode设置为”Multiline”时,文本框显示的行数

Columns       设置文本框的宽度

MaxLength     设置文本框允许输入的最多字符数

CheckBox控件

功能说明:用于创建复选框

命名前缀:Chk

ASPX代码:<asp:CheckBox ID=”ChkSample” runat=”server” Text=”CheckBox Sample” />

重要属性:Text          显示在复选框旁的文本

Checked       复选框的选择状态,True为选中,False为未选中

 

RadioButton控件

功能说明:用于创建单选按钮

命名前缀:Rad

ASPX代码:<asp:RadioButton ID=”RadSample” runat=”server” GroupName=”GroupOne” Text=”RadioButton Sample” />

重要属性:Text          显示在单选按钮旁的文本

GroupName     属于通一组的单选按钮,即GroupName相同的单选按钮,只能有一个处于选中状态

Checked       单选按钮的选择状态,True为选中,False为未选中

 

CheckBoxList控件

功能说明:用于创建一组复选框

命名前缀:ChkLst

ASPX代码:<asp:CheckBoxList ID=”ChkLstSample” runat=”server”>

<asp:ListItem Value=”1″>选项1</asp:ListItem>

<asp:ListItem Value=”2″>选项2</asp:ListItem>

</asp:CheckBoxList>

重要属性:Items         复选框列表中复选框集合

Selected      Items集合元素属性,对应复选框选择状态

 

RadioButtonList控件

功能说明:用于创建一组单选按钮

命名前缀:RadLst

ASPX代码:<asp:RadioButtonList ID=”RadLstSample” runat=”server”>

<asp:ListItem Value=”1″>选项1</asp:ListItem>

<asp:ListItem Value=”2″>选项2</asp:ListItem>

</asp:RadioButtonList>

重要属性:SelectedItem  单选按钮集合中选择状态为选中的单选按钮

ListBox控件

功能说明:用于创建列表框

命名前缀:Lst

ASPX代码:<asp:ListBox ID=”LstSample” runat=”server”>

<asp:ListItem Value=”1″>选项1</asp:ListItem>

<asp:ListItem Value=”2″>选项2</asp:ListItem>

</asp:ListBox>

重要属性:SelectionMode 列表框的的选择模式,”Single”为单项选择,”Multiline”为多项选择

Items         列表框的选项集合

Selected      Items集合元素属性,对应选项的选择状态,True为选中,False为未选中

 

DropDownList控件

功能说明:用于创建下拉列表框,只能进行单项选择

命名前缀:DdwLst

ASPX代码:<asp:DropDownList ID=”DdwLstSample” runat=”server”>

<asp:ListItem Value=”1″>选项1</asp:ListItem>

<asp:ListItem Value=”2″>选项2</asp:ListItem>

</asp:DropDownList>

重要属性:Items         复选框列表的选项集合

Selected      Items集合元素属性,对应选项的选择状态,True为选中,False为未选中

 

RequiredFieldValidator控件

功能说明:验证控件必须输入,未输入时或输入与初始值相同时提示错误信息

命名前缀:ReqVdt

ASPX代码:<asp:RequiredFieldValidator ID=”ReqVdtName” runat=”server”

ErrorMessage=”未输入姓名” ControlToValidate=”TxtSample”>

</asp:RequiredFieldValidator>

重要属性:ControlToValidate 被验证的控件的Name

ErrorMessage      验证失败的提示信息

InitialValue      InitialValue如果为空,被验证的控件的内容为空则验证失败,

如果不为空,被验证的控件的内容如果和InitialValue值一样则验证失败。

RangeValidator控件

功能说明:输入范围验证,输入值的范围必须在指定的范围之内。

命名前缀:RngVdt

ASPX代码:<asp:RangeValidator ID=”RngVdtSample” runat=”server”

ControlToValidate=”TxtAge” ErrorMessage=”年龄必须在1-150之间。”

Type=”Integer” MinimumValue=”1″ MaximumValue=”150″>

</asp:RangeValidator>

重要属性:ControlToValidate 被验证的控件的Name

ErrorMessage      验证失败的提示信息

Type              被验证数据的类型,可以是字符串、数值和日期型

MinimumValue      最小值

MaximumValue      最大值

 

CompareValidator控件

功能说明:验证输入值与指定值的大小关系,输入值必须符合与指定值的大小关系

命名前缀:CmpVdt

ASPX代码:<asp:CompareValidator ID=”CmpVdtSample” runat=”server”

ControlToValidate=”TxtBirthday” ErrorMessage=”生日不能晚于2009/8/31″

Type=”Date” perator=”LessThanEqual” ValueToCompare=”2009/8/31″>

</asp:CompareValidator>

重要属性:ControlToValidate 被验证的控件的Name

ErrorMessage      验证失败的提示信息

Type              被验证数据的类型,可以是字符串、数值和日期型

Operator          与指定值的大小关系

ValueToCompare    指定进行大小比较的值

ControlToCompare  指定进行大小比较的控件

RegularExpressionValidator控件

功能说明:通过正则表达式验证输入值

命名前缀:RegVdt

ASPX代码:<asp:RegularExpressionValidator ID=”RegVdtSample” runat=”server”

ControlToValidate=”TxtZip” ErrorMessage=”邮编格式不正确”

ValidationExpression=”\d{6}”>

</asp:RegularExpressionValidator>

重要属性:ControlToValidate     被验证的控件的Name

ErrorMessage          验证失败的提示信息

ValidationExpression  用于验证的正则表达式

 

CustomValidator控件

功能说明:通过自定义函数验证输入值

命名前缀:RegVdt

ASPX代码:<asp:CustomValidator ID=”CtmVdtSample” runat=”server”

ControlToValidate=”TxtSex” ErrorMessage=”性别应为男或女”

ClientValidationFunction=”ValidateSex” >

</asp:CustomValidator>

<script. type=”text/javascript”>

function ValidateSex(source,args)

{

args.IsValid = (args.Value==”男” || args.Value==”女”);

}

</script>

重要属性:ControlToValidate         被验证的控件的Name

ErrorMessage              验证失败的提示信息

ClientValidationFunction  客户端验证函数,args.Value为验证内容,args.IsValid为验证结果

OnServerValidate          服务端验证时间,通过事件过程实现,args.Value为验证内容,args.IsValid为验证结果

 

ValidationSummary控件

功能说明:汇总方式显示错误信息,如不希望显示内联验证控件的错误,将内联验证控件的Display属性设置为None,

或设置Text属性,验证错误时Validator控件显示Text,ValidationSummary控件显示ErrorMessage

命名前缀:VdtSum

ASPX代码:<asp:ValidationSummary ID=”VdtSumSample” runat=”server” ShowMessageBox=”True” ShowSummary=”False” />

重要属性:ShowMessageBox    以对话框显示错误信息

ShowSummary       在网页上显示错误信息

DisplayMode       显示错误信息方式

发表评论

[/0o0] [..^v^..] [0_0] [T.T] [=3-❤] [❤.❤] [^v^] [-.0] [!- -] [=x=] [→_→] [><] 更多 »
昵称

抢沙发~