ASP.NET AJAX 1.0 Sample
1 Partial Class _Default
2 Inherits System.Web.UI.Page
3
4 '' Label1 is inside Update Panel.
5 '' Button1 is inside Update Panel.
6
7 '' TextBox1 is outside Update Panel.
8 '' Button2 is outside Update Panel.
9
10 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
11 Me.Label1.Text = "Label"
12 Me.TextBox1.Text = "TextBox"
13 '' The content of Label1 has been changed into "Label".
14 '' The content of TextBox1 hasn't been changed.
15 End Sub
16
17 Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
18 Me.Label1.Text = "Label1"
19 Me.TextBox1.Text = "TextBox1"
20 '' Both of Label1 and TextBox has changed.
21 '' Their text have been changed into "Label1" and "TextBox1".
22 End Sub
23 End Class
2 Inherits System.Web.UI.Page
3
4 '' Label1 is inside Update Panel.
5 '' Button1 is inside Update Panel.
6
7 '' TextBox1 is outside Update Panel.
8 '' Button2 is outside Update Panel.
9
10 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
11 Me.Label1.Text = "Label"
12 Me.TextBox1.Text = "TextBox"
13 '' The content of Label1 has been changed into "Label".
14 '' The content of TextBox1 hasn't been changed.
15 End Sub
16
17 Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
18 Me.Label1.Text = "Label1"
19 Me.TextBox1.Text = "TextBox1"
20 '' Both of Label1 and TextBox has changed.
21 '' Their text have been changed into "Label1" and "TextBox1".
22 End Sub
23 End Class
从这一小段Sample可以看出,确实如Microsoft ASP.NET AJAX Documents所说,UpdatePanel内的更新不会影响到UpdatePanel外的更新。同样我们也可以看到,在默认情况下UpdatePanel内发出的更新如果请求UpdtePanel外的更新,也将被屏蔽掉,当然我们可以通过设置一些参数来获得我们希望得到的结果。
通过这个Sample我们大致可以看出新的ASP.NET AJAX启动了人为划分“控件作用域”的一个机制,如此一来通过人为划分来避免一些信息丢失或无用更新的发生,用人工规划代替原来的作用域以外全部否定的“智能规划”。