}
}
任务三:
设计一个小计算器,能够进行基本的加,减,乘,除运算即可,程序运行效果如图:
具体操作步骤: 1.建立网站: 2.设计页面:
3.添加控件及设置属性: 4.编写事件代码:
using System;
using System.Configuration; using System.Data; using System.Linq; using System.Web;
using System.Web.Security; using System.Web.UI;
using System.Web.UI.HtmlControls; using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts; using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e)
{
this.Title = \我的小计算器\ txtresult.ReadOnly = true;
14
}
protected void Button1_Click(object sender, EventArgs e) {
float fnum1 = 0, fnum2 = 0, fresult = 0; fnum1 = float.Parse(txtnum1.Text); fnum2 = float.Parse(txtnum2.Text);
string strope = dropclass.SelectedValue; switch (strope) {
case \
fresult = fnum1 + fnum2; break; case \
fresult = fnum1 - fnum2; break; case \
fresult = fnum1 * fnum2; break; case \
fresult = fnum1 / fnum2; break; }
txtresult.Text = fresult.ToString(); }
protected void Button2_Click(object sender, EventArgs e) {
txtnum1.Text = \ txtnum2.Text = \ txtresult.Text = \ }
}
任务四:
制作如图所示的用户注册页面,当单击“注册”按钮后就在Label控件中显示相应注册信息,当单击“重置”按钮后所有的信息清空。
15
具体操作步骤: 1.建立网站: 2.设计页面:
3.添加控件及设置属性: 4.编写事件代码:
using System;
using System.Configuration; using System.Data; using System.Linq; using System.Web;
using System.Web.Security; using System.Web.UI;
using System.Web.UI.HtmlControls; using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts; using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) { }
protected void Button1_Click(object sender, EventArgs e)
16
{
Label1.Text = \您的个人信息如下:
\ string message = \
message += \姓名:\ message += \密码:\
message += \性别:\ message += \出生日期:\
message += \专业:\+ ddlspeciality.SelectedItem.Text + \ message += \爱好:\
for (int j = 0; j < Chkhobby.Items.Count; j++) {
if (Chkhobby.Items[j].Selected == true) {
message += \ }
}
message += \联系地址:\ message += \邮政编码:\ message += \联系电话:\
message += \简介:\ Label1.Text += message; }
protected void Button2_Click(object sender, EventArgs e) {
txtname.Text = \ txtpwd.Text = \ txtpwd1.Text = \
Rdoltsex.ClearSelection(); txtbirthday.Text = \
ddlspeciality.ClearSelection(); Chkhobby.ClearSelection(); txtaddress.Text = \ txtyb.Text = \ txttel.Text = \
txtintroduction.Text = \ Label1.Text = \ }
}
任务五:
使用FILeUpLoad控件上传图象文件到Web服务器,并将图象文件在Image控件中显示出来,同时要显示出文件上传的相关信息。
程序启动后,由于没有上传图象,所以此时Image控件显示替换文本“尚未上传图象”如图;图象文件上传成功,提示“文件上传成功”,并在Image控件中显
17