Anthem设计实践----第二天 马上进入正题
Anthem的设计思路是在对Asp.net控件扩展,每一个控件都添加一个UpdataAfterCallBack的属性。对于实现常规控件无刷新更新信息,我们只需要设置这个属性为“true”就可以。在最初的尝试中我实现了下面的效果:
1. 页面上同步显示时间
2. 登录条模拟(登录之后自动显示:欢迎***)
3. 点击提交数据按钮之后,按钮不可用
4. 投票马上显示投票结果
――――――――――――――――――――――――――――
1.页面上同步显示时间
1 protected void Button1_Click(object sender, EventArgs e)
2 {
3 this.Label1.UpdateAfterCallBack = true;
4 this.TextBox1.UpdateAfterCallBack = true;
5 this.Label1.Text = DateTime.Now.ToString ();
6 this.TextBox1.Text = this.Label1.Text;
7 }
2 {
3 this.Label1.UpdateAfterCallBack = true;
4 this.TextBox1.UpdateAfterCallBack = true;
5 this.Label1.Text = DateTime.Now.ToString ();
6 this.TextBox1.Text = this.Label1.Text;
7 }
2. 登录条模拟(登录之后自动显示:欢迎***)
1 protected void Page_Load(object sender, EventArgs e)
2 {
3 this.TextBox3.TextMode = TextBoxMode.Password;
4 }
2 {
3 this.TextBox3.TextMode = TextBoxMode.Password;
4 }
1 protected void Button2_Click(object sender, EventArgs e)
2 {
3 this.Label2.UpdateAfterCallBack = true;
4 this.Label3.UpdateAfterCallBack = true;
5 this.Button2.UpdateAfterCallBack = true;
6 this.TextBox2.UpdateAfterCallBack = true;
7 this.TextBox3.UpdateAfterCallBack = true;
8 this.TextBox2.Visible = false;
9 this.TextBox3.Visible = false;
10 this.Button2.Visible = false;
11 this.Label3.Visible = false;
12 this.Label2.Text = "欢迎 "+this.TextBox2.Text +" 登录!";
13 }
2 {
3 this.Label2.UpdateAfterCallBack = true;
4 this.Label3.UpdateAfterCallBack = true;
5 this.Button2.UpdateAfterCallBack = true;
6 this.TextBox2.UpdateAfterCallBack = true;
7 this.TextBox3.UpdateAfterCallBack = true;
8 this.TextBox2.Visible = false;
9 this.TextBox3.Visible = false;
10 this.Button2.Visible = false;
11 this.Label3.Visible = false;
12 this.Label2.Text = "欢迎 "+this.TextBox2.Text +" 登录!";
13 }
3.点击提交数据按钮之后,按钮不可用
1 protected void Page_Load(object sender, EventArgs e)
2 {
3 this.Button1.UpdateAfterCallBack = true;
4
5 }
6 protected void Button1_Click(object sender, EventArgs e)
7 {
8 //button1是“提交数据按钮”
9 this.Button1.Enabled = false;
10 }
11 protected void Button2_Click(object sender, EventArgs e)
12 {
13 //button2是“撤销按钮”
14 this.Button1.Enabled = true;
15 }
2 {
3 this.Button1.UpdateAfterCallBack = true;
4
5 }
6 protected void Button1_Click(object sender, EventArgs e)
7 {
8 //button1是“提交数据按钮”
9 this.Button1.Enabled = false;
10 }
11 protected void Button2_Click(object sender, EventArgs e)
12 {
13 //button2是“撤销按钮”
14 this.Button1.Enabled = true;
15 }
4.投票马上显示投票结果
1protected void Button3_Click(object sender, EventArgs e)
2 {
3 this.RadioButtonList1.UpdateAfterCallBack = true;
4 this.Label4.UpdateAfterCallBack = true;
5 this.Button3.UpdateAfterCallBack = true;
6 for (int i = 0; i < this.RadioButtonList1.Items.Count;i++ )
7 {
8 if (this.RadioButtonList1.Items[i].Selected == true)
9 {
10 this.Label4.Text = "您已经选择了:" + this.RadioButtonList1.SelectedValue + " 感谢您的关注!";
11 }
12 }
13 this.RadioButtonList1.Visible = false;
14 this.Button3.Visible = false;
15 }
2 {
3 this.RadioButtonList1.UpdateAfterCallBack = true;
4 this.Label4.UpdateAfterCallBack = true;
5 this.Button3.UpdateAfterCallBack = true;
6 for (int i = 0; i < this.RadioButtonList1.Items.Count;i++ )
7 {
8 if (this.RadioButtonList1.Items[i].Selected == true)
9 {
10 this.Label4.Text = "您已经选择了:" + this.RadioButtonList1.SelectedValue + " 感谢您的关注!";
11 }
12 }
13 this.RadioButtonList1.Visible = false;
14 this.Button3.Visible = false;
15 }