在ASP.net 開發過程中常會使用到ListBox控制項,
有時會需要兩個以上的ListBox產生互動的情形
當點擇第一個ListBox時,第二個ListBox依據第一個ListBox所選取的項目來顯示資料
不過有時候因為資料量或網路的緣故,會導致第二個ListBox資料更新的速度過慢
這個時候可以透過jQuery Block UI的功能,避免資料還沒顯示,使用者又點選ListBox1

1. 在Page_Load中,替ListBox1加入onchange屬性

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
   If Not Me.IsPostBack Then
      Dim sScript As String
      sScript = "$.blockUI({ message: '<p>資料載入中,請稍後....!</p>' })"
      ListBox1.Attributes.Add("onchange", sScript)
   End If
End

2. 在ListBox1_SelectedIndexChanged中設定ScriptManager.RegisterStartupScript

Sub Protected Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
     System.Threading.Thread.Sleep(5000)
     Dim sScript As String  
     sScript = "$.unblockUI();"
     ScriptManager.RegisterStartupScript(Me, Me.GetType(), "unblock_UI", sScript, True)
End Sub
arrow
arrow
    文章標籤
    [學習筆記]jQuery
    全站熱搜

    rickyju 發表在 痞客邦 留言(0) 人氣()