欢迎来到天天文库
浏览记录
ID:61040412
大小:82.92 KB
页数:3页
时间:2021-01-20
《实验4 服务器控件的使用.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实验4服务器控件的使用目的与要求(1)掌握常用的Web服务器控件的使用方法。(2)熟悉各控件的常用属性和方法。(3)掌握验证控件的使用方法。内容和步骤【实验题4.1】使用Web服务器控件Label、TextBox和Button,设计如图p4.1所示的页面。使用C#语言,实现基本的加减乘除运算功能,并将计算结果输出。图4.1实验题4.1界面步骤如下:(1)启动VisualStudio2010,单击“创建:项目…”链接,即弹出“新建项目”对话窗口,左侧“项目类型”列表框选中选择“VisualC#→Web”;在“模板”列表框中
2、选择“ASP.NETWeb应用程序”。定义项目名称,并设置项目存储位置。(2)在Design视图,从Toolbox窗口选择若干控件,设置各控件属性及布局。(3)编写逻辑代码:protectedvoidPage_Load(objectsender,EventArgse){if(!IsPostBack){LabelNum1.Text=LabelNum2.Text="0";}}protectedvoidgetInputValue(objectsender,EventArgse){TBResult.Text+=((Butto
3、n)sender).Text;}protectedvoidDispose(objectsender,EventArgse){switch(((Button)sender).Text){case"+":LabelNum1.Text=TBResult.Text;LabelOperator.Text="+";TBResult.Text+=LabelOperator.Text;break;case"-":LabelNum1.Text=TBResult.Text;LabelOperator.Text="-";TBResult.Te
4、xt+=LabelOperator.Text;break;case"*":LabelNum1.Text=TBResult.Text;LabelOperator.Text="*";TBResult.Text+=LabelOperator.Text;break;case"/":LabelNum1.Text=TBResult.Text;LabelOperator.Text="/";TBResult.Text+=LabelOperator.Text;break;case"C":TBResult.Text="";LabelNum1
5、.Text=LabelNum2.Text="0";LabelOperator.Text="";break;}}protectedvoidcalculate(objectsender,EventArgse){switch(LabelOperator.Text){case"+":LabelNum2.Text=TBResult.Text.Substring(LabelNum1.Text.Length+1);TBResult.Text+="="+(Int32.Parse(LabelNum1.Text)+Int32.Parse(L
6、abelNum2.Text)).ToString();break;case"-":LabelNum2.Text=TBResult.Text.Substring(LabelNum1.Text.Length+1);TBResult.Text+="="+(Int32.Parse(LabelNum1.Text)–Int32.Parse(LabelNum2.Text)).ToString();break;case"*":LabelNum2.Text=TBResult.Text.Substring(LabelNum1.Text.Le
7、ngth+1);TBResult.Text+="="+(Int32.Parse(LabelNum1.Text)*Int32.Parse(LabelNum2.Text)).ToString();break;case"/":LabelNum2.Text=TBResult.Text.Substring(LabelNum1.Text.Length+1);TBResult.Text+="="+(double.Parse(LabelNum1.Text)/double.Parse(LabelNum2.Text)).ToString()
8、;break;}}}}(3)编译运行,结果如p4.2所示。图p4.2实验题4.1的运行结果【实验题4.2】使用Web服务器控件TextBox、Button、CheckBox、RadioButton、DropDownList、Image、Calendar、FileUpload等以及各种验证控件,设计如图p4.3所示的页
此文档下载收益归作者所有