您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 质量控制/管理 > web控件实验报告 含代码
实验名称基本控件实验实验目的熟练掌握各种控件的使用及事件的代码编写,能够掌握老师上课所讲的内容。实验设备MicrosoftVisualStudio2010实验过程(要求根据实现进行的过程,常用文字、图、表等描述,可另附页)1、创建Web窗体,使用Label控件显示文字“现在的时间是:”以及具体时间,自行设置其文字颜色、字体、字号、背景色等属性;增加一个Button按钮,要求当按下该按钮后能改变Label控件上文字的字体、字号、颜色和边框样式。如:代码为:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;publicpartialclass_Default:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){Label1.Text=现在的时间是+DateTime.Now.ToString();}protectedvoidButton1_Click(objectsender,EventArgse){Label1.Font.Name=宋体;Label1.Font.Size=12;Label1.BorderStyle=BorderStyle.Dotted;Label1.BorderColor=System.Drawing.Color.Blue;Label1.BackColor=System.Drawing.ColorTranslator.FromHtml(#cc00ff);Label1.ForeColor=System.Drawing.Color.Brown;Button1.Text=已改变样式;Button1.Enabled=false;}}运行结果为:2、创建Web窗体,该窗体上有一个TextBox控件和一个Button控件,要求每当用户单击按钮时,文本框会显示数据反映单击的次数。如:代码为:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;publicpartialclassDefault2:System.Web.UI.Page{staticinti;protectedvoidPage_Load(objectsender,EventArgse){if(!IsPostBack)TextBox1.Text=0;}protectedvoidButton1_Click(objectsender,EventArgse){i=i+1;TextBox1.Text=i.ToString();}}运行结果为:3、创建Web窗体,其中包含三种不同类型的TextBox,分别为单行、密码和多行文本框,如果用户在密码框中输入的密码少于8位或大于15位,就弹出错误提示对话框,运行效果如下:代码为:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;publicpartialclassDefault3:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){}protectedvoidTextBox2_TextChanged(objectsender,EventArgse){if(TextBox2.Text.Length8||TextBox2.Text.Length15)Response.Write(scriptalert('密¨¹码?必À?须?在¨²8位?到Ì?15位?之?间?')/script);}protectedvoidButton1_Click(objectsender,EventArgse){}protectedvoidTextBox3_TextChanged(objectsender,EventArgse){}}运行结果为:4、4、利用image控件、button控件实现图片的更换,显示比例的调整。代码为:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;publicpartialclassDefault4:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){}protectedvoidButton1_Click(objectsender,EventArgse){if(Image1.ImageUrl==~/image/1.jpg)Image1.ImageUrl=~/image/2.jpg;elseImage1.ImageUrl=~/image/1.jpg;}protectedvoidTextBox1_TextChanged(objectsender,EventArgse){}protectedvoidButton2_Click(objectsender,EventArgse){doubleh=Image1.Height.Value;doublew=Image1.Width.Value;doublebl=Convert.ToDouble(TextBox1.Text);Image1.Height=newUnit(h*bl);Image1.Width=newUnit(w*bl);}}运行结果为:5、利用linkbutton控件的command事件实现图像的变换。代码为:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;publicpartialclassDefault5:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){}protectedvoidLinkButton_Command(objectsender,CommandEventArgse){Image1.ImageUrl=~/image/+e.CommandName.ToString()+.jpg;}protectedvoidLinkButton2_Click(objectsender,EventArgse){}}运行结果为:6、使用CheckBox和RadioButton控件进行男女生喜欢的手机品牌调查,单击“确定”按钮后,将用户选择的信息显示出来,如:代码为:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;publicpartialclassDefault6:System.Web.UI.Page{protectedvoidButton1_Click(objectsender,EventArgse){if(RadioButton1.Checked)Label1.Text=你?是º?男D生¦¨²,ê?;elseLabel1.Text=你?是º?女?生¦¨²,ê?;Strings1,s2,s3;if(CheckBox1.Checked==true)s1=iphone;elses1=;if(CheckBox2.Checked==true)s2=三¨y星?;elses2=;if(CheckBox3.Checked==true)s3=小?米¡Á;elses3=;Label2.Text=你?喜2欢?的Ì?手º?机¨²是º?:êo+s1+s2+s3;}protectedvoidRadioButton1_CheckedChanged(objectsender,EventArgse){}protectedvoidRadioButton2_CheckedChanged(objectsender,EventArgse){}protectedvoidCheckBox1_CheckedChanged(objectsender,EventArgse){}protectedvoidCheckBox2_CheckedChanged(objectsender,EventArgse){}protectedvoidCheckBox3_CheckedChanged(objectsender,EventArgse){}}运行结果为:7、使用CheckBoxList控件显示班长候选人,单击“投票”按钮,将选择的候选人的名字显示在Label控件中,运行效果如下:代码为:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;publicpartialclassDefault7:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){}protectedvoidCheckBoxList1_SelectedIndexChanged(objectsender,EventArgse){}protectedvoidButton1_Click(objectsender,EventArgse){Strings=您¨²投ª?票¡À给?了¢?:êo;for(inti=0;i9;i++){if(CheckBoxList1.Items[i].Selected)s=s+CheckBoxList1.Items[i].Text;}Label2.Text=s;}}运行结果为:实验结论分析与实验体会通过本次实验,初步了解了标准的web服务器控件的使用,加深了对web网页设计的了解,也从七个小练习中循序渐进的熟练运用web服务器控件。教师评语与评分
本文标题:web控件实验报告 含代码
链接地址:https://www.777doc.com/doc-4877137 .html