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
@Downvoter - 謹慎評論? – Oded