您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 销售管理 > ASPNET服务器控件实验报告
ASP.NET实验报告题目:ASP.NET服务器控件院系:计算机科学与工程学院【实验题目】ASP.NET服务器控件【实验目的】1.熟悉用户控件的使用。2.熟悉导航控件的使用。3.掌握母版页的使用。【实验内容】设计一个个人情况调查程序,程序启动后显示如图所示的页面。用户在填写了姓名、选择了性别、喜爱的歌手、居住城市、个人爱好后单击“提交”按钮后,屏幕显示用户填写或选择的数据信息。若用户没填写姓名就单击“提交”按钮,屏幕显示出错提示信息;若用户没有选择“爱好”项目,单击“提交”按钮,“爱好”项目栏中显示“真可惜,你没有任何爱好!”。(1)打开VisualStudio2010创建一个网站,在Default.aspx页面上进行页面的设计,此时可以切换到设计视图,也可以使用拆分视图方便对照。(2)设计Web页面Web页面中标题“个人情况调查”为图片格式,在下面已经给出,请同学们右键单击下面的图片,保存到本地硬盘,再在程序中通过ImageMap控件添加进页面。附件:(3)设置对象属性Web页面中需包含以下控件,Label控件、TextBox控件、Button控件、LinkButton控件、ImageMap控件、RadioButton控件、DropDownList控件、ListItem控件、RadioButtonList控件、CheckBoxList控件等控件,并设置好每个对象的属性。开发界面如图3-1所示。图3-1程序开发界面(4)编写事件代码(5)运行和调试程序程序最终运行界面如图3-2所示。图3-2程序运行界面【实验代码】%@PageLanguage=C#AutoEventWireup=trueCodeFile=Default.aspx.csInherits=_Default%!DOCTYPEhtmlPUBLIC-//W3C//DTDXHTML1.0Transitional//EN==servertitleASP.NET服务器控件的使用/title/headbodystyle=text-align:leftformid=form1runat=serverdivstyle=text-align:leftasp:ImageMapID=ImageMap1runat=serverHeight=100pxWidth=470pxImageUrl=~/exp-3.jpg/asp:ImageMapspanstyle=font-size:16ptstrongbr//strong/spantableborder=1style=text-align:lefttrtdstyle=width:125px姓名asp:TextBoxID=txtNamerunat=serverWidth=77px/asp:TextBox/tdtdcolspan=2style=width:329px;text-align:left 性别asp:RadioButtonID=radSex1runat=serverChecked=TrueGroupName=seleSexText=男/asp:RadioButtonID=radSex2runat=serverGroupName=seleSexText=女//td/trtrtdstyle=width:125px你喜爱的歌手是/tdtdcolspan=2style=width:329px;text-align:left asp:DropDownListID=dropSingerrunat=serverasp:ListItem五月天/asp:ListItemasp:ListItem李宗盛/asp:ListItemasp:ListItem梁静茹/asp:ListItemasp:ListItem张惠妹/asp:ListItemasp:ListItem汪峰/asp:ListItem/asp:DropDownList/td/trtrtdstyle=width:125px你家住哪里/tdtdcolspan=2style=width:329px;text-align:leftasp:RadioButtonListID=radlHomerunat=serverRepeatColumns=4asp:ListItemSelected=True长春/asp:ListItemasp:ListItem吉林/asp:ListItemasp:ListItem沈阳/asp:ListItemasp:ListItem其他城市/asp:ListItem/asp:RadioButtonList/td/trtrtdstyle=width:125px;height:26px你的爱好是/tdtdcolspan=2style=width:329px;height:26px;text-align:leftasp:CheckBoxListID=chklLikerunat=serverRepeatColumns=4asp:ListItem篮球/asp:ListItemasp:ListItem足球/asp:ListItemasp:ListItem上网/asp:ListItemasp:ListItem音乐/asp:ListItem/asp:CheckBoxList/td/trtrtdstyle=width:125px;height:26px /tdtdcolspan=2style=width:329px;height:26px;text-align:leftasp:ButtonID=btnOKrunat=serverOnClick=btnOK_ClickText=提交//td/tr/tablebr//div asp:LabelID=lblNamerunat=server/asp:Labelbr/br/ asp:LabelID=lblHomerunat=server/asp:Labelbr/ br/ asp:LabelID=lblLikerunat=server/asp:Labelbr/br/br/br//form/body/htmlusingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;publicpartialclass_Default:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){this.Title=个人情况调查;txtName.Focus();}protectedvoidbtnOK_Click(objectsender,EventArgse){if(txtName.Text==){lblName.Text=b你必须输入姓名!/b;return;}stringstrSex=,strLike=;inti;if(radSex1.Checked){strSex=男;}else{strSex=女;}for(i=0;i=chklLike.Items.Count-1;i++){if(chklLike.Items[i].Selected){strLike=strLike+chklLike.Items[i].Text+,;}}strLike=strLike.Remove(strLike.Length-1,1);lblName.Text=txtName.Text+,+strSex+,+你喜欢的歌手是:+dropSinger.Text;lblHome.Text=你家住在:+radlHome.SelectedItem.Text;if(strLike==){strLike=真可惜,你没有任何爱好!;}else{strLike=你的爱好是:+strLike;}lblLike.Text=strLike;}}【实验结果】【实验心得】通过本次实验,我知道了如何通过ASP.NET创建服务器控件,加强了对控件的掌握,同时也加强了我对界面布局的掌握。在本次实验中,通过对ImageMap控件的使用,我知道了怎么通过控件将图片插入到程序界面中,让我觉得ASP.NET非常有意思。
本文标题:ASPNET服务器控件实验报告
链接地址:https://www.777doc.com/doc-6105101 .html