Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5980813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:51:18+00:00 2026-05-22T21:51:18+00:00

The code below displays a thumbnail of each image in a specific server directory

  • 0

The code below displays a thumbnail of each image in a specific server directory and when I click on the image it pops up a nice full sized picture. It works perfectly.

I would however, like to be able to delete an image. I first thought I could have a button at the bottom of the page with a checkbox next to each image, giving it a uniqueID as per the filename but as they are dynamically created I couldn’t figure how to handle the Click Event on the button for a randomly named Checkbox ID. Then I tried adding a button next to each item and then tried an OnClick & OnServerClick to call a Sub but this didn’t work either.

Any/All suggestions welcomed 🙂

Private Sub ImageList()
        If Directory.Exists(Server.MapPath("JobImages\" & DBC_JOB_JobID.Text)) Then
            Dim MySB As New StringBuilder
            Dim dirInfo As New DirectoryInfo(Server.MapPath("JobImages\" & DBC_JOB_JobID.Text))
            MySB.Append("<ul class=""clearfix"">")
            MySB.AppendLine()
            For Each File In dirInfo.GetFiles()
                MySB.Append("<li><a rel=""jobpic"" href=""JobImages\" & DBC_JOB_JobID.Text & "\" & File.Name & """><img src=""JobImages\" & DBC_JOB_JobID.Text & "\Thumbs\" & File.Name & """ width=""150"" height=""100"" /> <span class=""size"">" & File.Name & " </span></a></li>")
                MySB.AppendLine()
            Next
            MySB.Append("</ul>")
            MySB.AppendLine()
            lblMyPictures.Text = MySB.ToString
        End If
    End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:51:18+00:00Added an answer on May 22, 2026 at 9:51 pm

    OK what Kendrick is talking about (basically) is using server side controls to keep track of which file to delete. What you are doing right now is dumping markup into a Label control, which on postback won’t fire an event on the server side. However you can accomplish this easily with server side controls.

    The basic idea is you use a container control such as a Panel and add each child control to it. Then you hook events to each row with data identifying that row (such as filename).

    Markup:

        <asp:Panel ID="pnlList" runat="server">
        </asp:Panel>
    

    Code-Behind:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Directory.Exists(Server.MapPath("Files")) Then
            Dim objDirInfo As New DirectoryInfo(Server.MapPath("Files"))
            For Each objFile As FileInfo In objDirInfo.GetFiles()
                Dim objLabel As New Label
                objLabel.Text = objFile.Name
    
                Dim objLinkButton As New LinkButton
                objLinkButton.Text = "Delete"
                objLinkButton.CommandName = "Delete"
                objLinkButton.CommandArgument = objFile.Name
                AddHandler objLinkButton.Command, AddressOf DeleteFile
    
                Dim objLiteral As New LiteralControl
                objLiteral.Text = "<br/>"
    
                pnlList.Controls.Add(objLabel)
                pnlList.Controls.Add(objLinkButton)
                pnlList.Controls.Add(objLiteral)
            Next
        End If
    
    End Sub
    
    Public Sub DeleteFile(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs)
        If e.CommandName = "Delete" Then
            Dim strFileName As String = Server.MapPath("Files\" & e.CommandArgument)
            If File.Exists(strFileName) Then
                Dim objFile As New FileInfo(strFileName)
                objFile.Delete()
            End If
        End If
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the code below, $row['site'] is an URL. In Chrome and IE8, it displays
The below HTML/CSS/Javascript (jQuery) code displays the #makes select box. Selecting an option displays
I am using the code below to get the attached images for each post
The code below works fine at 1280x800, however, if I add another thumbnail, the
the code below displays a radial gradient filled rectangle. If I un-comment the two
The Code below displays a dialog after clicking on a ListView's Item.I would instead
The pagination code below displays nicely. However, it is always left-justified against the edge
The code snippet below displays a Dialog with a simple login-form. The problem is
I have the following unorderered list code which displays the list below: <ul> <li
My code below displays 10 entries, but it displays it in 10 rows and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.