2022年WEB服务器控 .pdf





《2022年WEB服务器控 .pdf》由会员分享,可在线阅读,更多相关《2022年WEB服务器控 .pdf(25页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、WEB 服务器控件编写一个 WEB 控件至少要包含三个元素:ASP:XXX指明是哪一类控件,ID 指明控件的标识符,Runat 指明是在服务器端运行的。如: 一、WEB 服务器控件1、 常用的 WEB 服务器控件分类名称说明文字控件Label 标签TextBox 文本框选择控件Checkbox 复选框Checkboxlist 复选框列表Radiobutton 单选按钮Radiobuttonlist 单选按钮列表Dropdownlist 下拉列表框Listbox 列表框按钮Button 按钮Image 图像控件Imagebutton 图像按钮超链接Hyperlink 超链接控件Li
2、nkbutton 超链接按钮控件2、WEB 控件的公有属性属性说明AccessKey 获取或设置控件的键盘快捷键BackColor 获取或设置控件的背景色BorderColor 获取或设置控件的边框颜色BorderWidth 控件的边框宽度BorderStyle 控件的边框样式CssClass 分配给控件的样式表类Enable 控件是否有效Font 控件的字体ForeColor 控件的前景色Height 控件的高度Width 控件的宽度Visible 控件是否可见ToolTip 获取或设置当用户将鼠标指针停放在控件上时显示的文本3、通过编程设置WEB 服务器控件的属性如 label1.Text
3、=” 您好 ” ; TextBox1.TextMode=TextBoxMode.SingleLine; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 25 页 - - - - - - - - - 二、文字控件Label 用于显示文字,其最常用的属性是Text, 用于显示的文字内容。 TextBox控件用于输入文字信息, WEB 用于文本输入工作的只有TextBox 控件,通过设置控件的TextMode 属性来区分文本,密码,多行文本输入方式。注意:文本框内容是字符串类型
4、,如果要做计算,需要作类型转换。如convert.tosingle转成单精度,或single.parse() TextBox 主要成员成员说明AutoPostBack 文本框内容发生变化,并且输入焦点离开文本框(TAB,ENTER ) ,是否自动将文本框内容发回服务器。Text 文本框中内容TextMode SingleLine 单行输入模式,默认 MultiLine 多行Password密码输入Columns 以字符为单位指明文本框的显示宽度Rows 当 TextMode 为 MultiLine 时,指明文本框的行数MaxLength 在单行文本方式下,文本框可以输入的字符数Wrap 当 T
5、extMode 为 MultiLine 时 ,是否自动换行,默认为TRUE ReadOnly 输入框为只读,默认为FALSE DataBind() 将数据源绑定到被调用的服务器控件及其所有子控件上TextChanged() 当文本框内容发生变化时,触动。文字控件案例一 (5_3):制作登录界面控件类型ID 属性设置说明Label Label1 Text=用户名用于显示静态文本Label Label2 Text=密码用于显示静态文本Label LblMessage Text=”用于显示提示文本或登录信息TexBox TxtUserName TextMode=SingleLine 用于输入用户名T
6、exBox TxtPassWord TextMode=Password 用于输入密码Button BtnSumit Text=提交向服务器发送登录信息Button BtnRest Text=重置清除文本框内容名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 25 页 - - - - - - - - - protectedvoid BtnRest_Click(object sender, EventArgs e) TxtUserName.Text = ; TxtPassWor
7、d.Text = ; LblMessage.Text = ; protectedvoid BtnSumit_Click(object sender, EventArgs e) if (TxtUserName.Text.Trim() != ) & (TxtPassWord.Text.Trim() != ) LblMessage.Text = 用户名 : + TxtUserName.Text + 密码 + :+TxtPassWord.Text; elseif (TxtUserName.Text.Trim() = ) LblMessage.Text = 请输入用户名 ; else LblMessag
8、e.Text = 请输入密码 ; 文本控件案例二 (5_1):显示日期protectedvoid Page_Load( object sender, EventArgs e) DateTime now = DateTime.Now; this .lbltime1.Text = now.ToString(); this .lbltime2.Text = now.ToShortDateString(); this .lbltime3.Text = now.ToLongDateString(); this .lbltime4.Text = now.ToLongTimeString(); this .
9、lbltime5.Text = now.ToShortTimeString(); 文本控件案例三 (5_2):显示金额protectedvoid Button1_Click(object sender, EventArgs e) int money = Convert .ToInt32(TextBox1.Text); Label1.Text = money.ToString(C); Label2.Text = money.ToString($#,#.00); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - -
10、- - - - - 第 3 页,共 25 页 - - - - - - - - - 练习: 制作页面 , 完成阶乘运算。三、选择控件选 择 控 件 包 含CheckBox CheckBoxList DropDownList ListBox RadioButton RadioButtonList等控件1、RadioButton 是多选一的控件, 因此该控件还有一个专门的GroupName属性,同一组别的RadioButton控件的 GroupName属性必须相同。控件的主要成员成员说明Checked 是否选中该控件GroupName 获取或设置单选钮所属的组名Text 文本标签TextAlign
11、文本标签的对齐方式,文本出现在左边还是右边。CheckedChanged 当 checked 的值在向服务器发送期间更改时发生选择控件案例一(5_4) :单选按钮应用添加两个单选按钮控件,Text 的值分别设为“男”,“女”,GroupName 的值为 sex。protectedvoid Button1_Click(object sender, EventArgs e) if (RadioButton1.Checked = true ) Label1.Text = 性别 : + RadioButton1.Text; if (RadioButton2.Checked = true ) Label
12、1.Text = 性别: + RadioButton2.Text; 练习:完成选择系单选设计功能。2、CheckBox 控件属性和 RadioButton一样。名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 25 页 - - - - - - - - - 选择控件案例二(5_5) :复选控件应用添加三个复选按钮,Text 的值按照以上图中设置。protectedvoid Page_Load( object sender, EventArgs e) Label1.Text =
13、 ; protectedvoid Button1_Click(object sender, EventArgs e) string str1 = 你的选择是 : ; if (CheckBox1.Checked) str1 += CheckBox1.Text + ; if (CheckBox2.Checked) str1 += CheckBox2.Text + ; if (CheckBox3.Checked) str1 += CheckBox3.Text ; Label1.Text = str1; 练习:完成选择课程复选功能设计3、CheckBoxList 和RadioButtonList控件主
14、要成员成员说明Items 属性获取列表项控件的集合,有以下常用属性和方法Count属性:集合中对象数Add方法:将 ListItem追加到集合的末尾Clear 方法:从集合中移除所有的ListItem对象Remove 方法:从集合中移除指定ListItem对象RepeatColumns属性设置控件中显示的列数RepeatDirection属性水平还是垂直显示名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 25 页 - - - - - - - - - SelectedInd
15、ex属性选定项的索引序号SelectedValue属性选定项的值选择控件案例三(5_6) :单选复选组应用IsPostBack != true判断页面是否首次加载或刷新。因为每次在执行button_click时,都会先执行page_load ,如果不想执行,则用IsPostBack != trueprotectedvoid Page_Load( object sender, EventArgs e) if (IsPostBack != true ) string player = new string3 姚明 , 科比 , 邓肯 ; string team=new string3 小牛 , 太
16、阳 , 火箭 ; RadioButtonList1.DataSource = player; RadioButtonList1.DataBind(); CheckBoxList1.DataSource = team; CheckBoxList1.DataBind(); protectedvoid Button1_Click(object sender, EventArgs e) Label1.Text = 你最喜欢的球员是 ; Label1.Text += RadioButtonList1.SelectedValue;int i = 0; string s = ; for (i = 0; i
17、0) int i; for (i = 0; i = ListBox1.Items.Count - 1; i+) ListBox2.Items.Add(ListBox1.Itemsi.Text); ListBox1.Items.Clear(); protectedvoid Button4_Click(object sender, EventArgs e) int i; for (i = 0; i 0 & ListBox1.SelectedIndex = -1) else for (i = 0; i 0 & ListBox2.SelectedIndex = -1) else for (i = 0;
18、 i = ListBox2.Items.Count - 1; i+) if (ListBox2.Itemsi.Selected) ListBox1.Items.Add(ListBox2.Itemsi.Text); ListBox2.Items.Remove(ListBox2.Itemsi); ( 一班 ) 选择控件案例七( 5_10)控件的联动protectedvoid Page_Load( object sender, EventArgs e) /DropDownList1.AutoPostBack = true; if (IsPostBack != true ) string zy = n
19、ew string2 临汾 , 吕梁 ; DropDownList1.DataSource = zy; DropDownList1.DataBind(); DropDownList1.SelectedIndex = 0; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 13 页,共 25 页 - - - - - - - - - protectedvoid DropDownList1_SelectedIndexChanged(object sender, EventArgs e) Ar
20、rayList sz = new ArrayList(); if (DropDownList1.Items0.Selected) sz.Add(霍州 ); sz.Add(候马 ); if (DropDownList1.Items1.Selected) sz.Add(吕梁 ); sz.Add(中阳 ); ListBox1.DataSource = sz; ListBox1.DataBind(); 注意:AutoPostBack是用在一个控件中的值变换会带来另一个控件值变换时,需要设置为true, 它的AutoPostBack属性默认为 False, 如果不把属性改为True, 他的 Select
21、edIndexChanged()事件中的代码就不会执行练习:设置系和专业联动,添加按钮及标签,显示选定结果。四、按钮控件1、 Button 2、ImageButton 从功能上看和 Button 控件一样 , 但是该控件是用图片作为按钮的表面。有两个属性:ImageUrl :设置图片所在位置ToolTip :鼠标定们图片后显示的文字按钮控件案例一(5_12)名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 14 页,共 25 页 - - - - - - - - - protectedv
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年WEB服务器控 2022 WEB 服务器

限制150内