How do I prevent the page from reloading when ever I click on a checkbox?
This can be cumbersome when I have hundreds of checkboxes.
Below is my code:
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>
I believe I set AutoPostBack=True because of the below code:
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
Set AutoPostBack to False to prevent the page from reloading. Then depends on what you are trying to do with the checkbox after doing that change.