每次标记复选框时,VB.NET页面都会重新加载

时间:2011-10-19 19:46:35

标签: asp.net 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 = True是因为下面的代码:

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 个答案:

答案 0 :(得分:7)

你有AutoPostBack="True"。如果您不希望它自动回发,请将其设置为False

答案 1 :(得分:2)

将AutoPostBack设置为False以防止页面重新加载。然后取决于您在执行此更改后要使用复选框执行的操作。