2011-10-19 70 views
2

當我點擊複選框時,如何防止頁面重新加載? 當我有數百個複選框時,這可能很麻煩。 下面是我的代碼:VB.NET每當我標記一個複選框時,頁面將重新加載

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
If Not Page.IsPostBack Then 
    Dim di As New IO.DirectoryInfo(ImagePath) 
    Dim imageArray As IO.FileInfo() = di.GetFiles() 
    Dim image As IO.FileInfo 

    'list the names of all images in the specified directory 

    For Each image In imageArray.OrderBy(Function(i) i.Name) 
     CheckBoxList1.Items.Add(image.Name) 
    Next 
End If 
End Sub 

ASP.NET:

<asp:CheckBoxList ID="CheckBoxList1" runat="server" RepeatLayout="table" RepeatColumns="4" RepeatDirection="vertical" AutoPostBack="True"> 
    </asp:CheckBoxList> 

我相信我設定的AutoPostBack =真,因爲下面的代碼:

Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnDelete.Click 

    For count As Integer = 0 To CheckBoxList1.Items.Count - 1 
     If CheckBoxList1.Items(count).Selected Then 
      File.Delete(ImagePath & CheckBoxList1.Items(count).ToString) 
      CheckBoxList1.Items.Remove(count) 
     End If 
    Next 

    Response.Redirect("Delete.aspx") 

End Sub 

回答

2

將AutoPostBack設置爲False以防止重新加載頁面。然後取決於你做了這個改變後你想用複選框做什麼。

7

你有AutoPostBack="True"。如果您不希望它自動回發,請將其設置爲False

+0

@Downvoter - 謹慎評論? – Oded

相關問題