I do have something working for deleting Albums. I think this is all I did (I don't have a source control system to diff my new files with original, so am going from what I know I changed :)
Added OnClick event for the delete button to take user back to the list of albums. Source below: protected void deleteButton_Click(object sender, System.EventArgs e)
{
Response.Redirect("~/PhotoAlbum_List.aspx", false);
}
Added a Delete command for the SQL in <asp:SqlDataSource ID="SqlDataSource1" runat="server" ASP code added:
DeleteCommand="DELETE FROM Albums WHERE (albumid = @albumid)"
<DeleteParameters>
<asp:Parameter Name="albumid" />
</DeleteParameters>
If you delete an album, you would more than likely want to delete the images as well. So, I found that an easy way to do this was to set the Action on the Album table in SQL Express to OnDeleteCascade. See this post:
http://forums.asp.net/thread/995085.aspx
I think that's all I had to do. So far my testing hasn't stumbled across any problems. I've tested deleting albums with 0 to many images and am not receiving errors. Even the redirect back to the list of albums works. Note that in that method above, I set
the second parameter to False, this allows the Delete code to continue to execute when the browser moves back to the list. If set to True, the deltion does not occur. I suppose I could use a different event, but it's working for now.
Thanks,
Gary
Having just started the whole ASP thing and the club starter kit I have found even the oldest post valuable. So I thought I'd put my two cents in on the deleting album and admin only visible idea. Bits and pieces are from other postings including this
one but I thought it best to put in what worked for me with the combinations. This is built on the CSK 1. Sorry, can't figure out why I have such spacing between lines, ignore please.
In PhotoAlbum_Contents.aspx:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
IsAdmin = User.IsInRole("Administrators") Or User.IsInRole("Users")
IsAdminLocked = User.IsInRole("Administrators")
uploadpanel.Visible = IsAdmin
THEN ADDED delete button (it was missing) to <item template>
<div class="actionbuttons">
<Club:RolloverButton ID="editButton" CommandName="Edit" Text="Edit Album Details" runat="server" Visible='<%#IsAdmin %>' />
I did discover there are some other things that should be done when deleting and Image or an Album.
If you used an image from an album on an Event or News item, and then deleted that image, or the album containing that image, you could receive errors. I forget where there errors were, but it was one of the following:
Events_Edit.aspx and News_Edit.aspx in < Club:Photopicker
ID="Photopicker1"
runat="server"
ImageId='<%# Bind("photo") %>'
/>
or
ImageFetch.ashx in output.Write(d, 0, d.Length);
I don't remember for sure anymore.
I modified the DeleteCommand for both image and album on PhotoAlbum_Contents.aspx:
DeleteCommand="DELETE FROM Albums WHERE (albumid = @albumid);
UPDATE Announcements SET Photo=0 WHERE (albumid = @albumid);
UPDATE Events SET Photo=0 WHERE (album = @albumid);
UPDATE Announcements SET albumid=Null WHERE (albumid = @albumid);
UPDATE Events SET album=Null WHERE (album = @albumid);"
DeleteCommand="DELETE FROM images WHERE (id = @id);
UPDATE Announcements SET photo=0 WHERE (photo = @id);
UPDATE Events SET photo=0 WHERE (photo = @id)"
Setting Photo columns to 0 and the album columns to null resovled the issues I had.
Now, if I delete an image or album that I used on a news/event item, I don't have any issues. the items simply appear without an image as expected.
thanks,
gary
Marked as answer by TATWORTH on Nov 28, 2009 04:05 PM
hi i am verrry new to c#.net so if this answer sound stupid, sorry. i am running the club site and wanted to delete the photo album too, so i just commented out the link to it in the site map and left it in without a way to get to it. i don't know if this
is the right way to do it but it does work. hope it helps
The easiest way to handle this is to put a DELETE TRIGGER on the Albums table that'll cascade the delete to all the corresponding images in the Photos table. As for the missing photos issue, there is some logic in the Events_List.aspx page (specifically
the Repeater) to handle no pictures:
<asp:Repeater ID="rpEvents" runat="server" DataSourceID="sdsEvents">
<ItemTemplate>
<div>
<div>
<a href='<%# "Events_view.aspx?Eventid=" Eval("ID").toString()%>'>
<Club:ImageThumbnail ID="ImageThumbnail1" runat="server" PhotoID='<%# Eval("photo") %>'
NoPhotoImg="images/calendar.jpg" /> <--- image stored in \images on file system
And in the code, make sure you handle/ceck for null values so things don't choke if there's no picture.
glura
Member
122 Points
44 Posts
Deleting a Photo Album
Jul 04, 2006 04:11 PM|LINK
Does anyone have an example or tips for what needs to be done to delete a photo album?
I know I'll have to do something like: DELETE FROM Albums WHERE (albumid = @albumid)
But I also need to delete all images associated with that album.
I'm also not sure what to do after the delete completes? For example, what page should display?
any advice would be appreciated.
Thanks,
Gary
glura
Member
122 Points
44 Posts
Re: Deleting a Photo Album
Nov 10, 2006 05:56 AM|LINK
I do have something working for deleting Albums. I think this is all I did (I don't have a source control system to diff my new files with original, so am going from what I know I changed :)
Work done on PhotoAlbum_Contents.aspx:
Added Delete button to <ItemTemplate>. Source below:
<div class="actionbuttons">
<Club:RolloverButton ID="editButton" CommandName="Edit" Text="Edit Album Details" runat="server" Visible='<%#IsAdmin %>' />
<Club:RolloverButton ID="deleteButton" CommandName="Delete" Text="Delete" runat="server" Visible='<%#IsAdmin %>' OnClick="deleteButton_Click"/>
</div>
Added OnClick event for the delete button to take user back to the list of albums. Source below: protected void deleteButton_Click(object sender, System.EventArgs e)
{
Response.Redirect("~/PhotoAlbum_List.aspx", false);
}
Added a Delete command for the SQL in <asp:SqlDataSource ID="SqlDataSource1" runat="server" ASP code added:
DeleteCommand="DELETE FROM Albums WHERE (albumid = @albumid)"
<DeleteParameters>
<asp:Parameter Name="albumid" />
</DeleteParameters>
If you delete an album, you would more than likely want to delete the images as well. So, I found that an easy way to do this was to set the Action on the Album table in SQL Express to OnDeleteCascade. See this post: http://forums.asp.net/thread/995085.aspx
I think that's all I had to do. So far my testing hasn't stumbled across any problems. I've tested deleting albums with 0 to many images and am not receiving errors. Even the redirect back to the list of albums works. Note that in that method above, I set the second parameter to False, this allows the Delete code to continue to execute when the browser moves back to the list. If set to True, the deltion does not occur. I suppose I could use a different event, but it's working for now.
Thanks,
Gary
Delete Album
jeaninel
Member
4 Points
5 Posts
Re: Deleting a Photo Album
Aug 21, 2009 10:24 PM|LINK
Having just started the whole ASP thing and the club starter kit I have found even the oldest post valuable. So I thought I'd put my two cents in on the deleting album and admin only visible idea. Bits and pieces are from other postings including this one but I thought it best to put in what worked for me with the combinations. This is built on the CSK 1. Sorry, can't figure out why I have such spacing between lines, ignore please.
In PhotoAlbum_Contents.aspx:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
IsAdmin = User.IsInRole("Administrators") Or User.IsInRole("Users")
IsAdminLocked = User.IsInRole("Administrators")
uploadpanel.Visible = IsAdmin
THEN ADDED delete button (it was missing) to <item template>
<div class="actionbuttons">
<Club:RolloverButton ID="editButton" CommandName="Edit" Text="Edit Album Details" runat="server" Visible='<%#IsAdmin %>' />
<Club:RolloverButton ID="deleteButton" CommandName="Delete" Text="Delete" runat="server" Visible='<%#IsAdminLocked %>' OnClick="deleteButton_Click"/></div>
Modified Delete command in <asp:SqlDataSource runat="server" to:
DeleteCommand="DELETE FROM Albums WHERE (albumid = @albumid); DELETE FROM Images WHERE (album = @albumid)"
<DeleteParameters>
<asp:Parameter />
</DeleteParameters>
Hope this helps someone.
jeaninel
Member
4 Points
5 Posts
Re: Deleting a Photo Album
Aug 22, 2009 12:30 AM|LINK
Sorry, I was interrupted and didn't add this code to my previous post.
Added OnClick event for the delete button to take user back to the list of albums.
Protected Sub deleteButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Response.Redirect("~/PhotoAlbum_List.aspx", False)
End Sub
glura
Member
122 Points
44 Posts
Re: Deleting a Photo Album
Nov 22, 2009 02:01 AM|LINK
I did discover there are some other things that should be done when deleting and Image or an Album.
If you used an image from an album on an Event or News item, and then deleted that image, or the album containing that image, you could receive errors. I forget where there errors were, but it was one of the following:
Events_Edit.aspx and News_Edit.aspx in < Club:Photopicker ID="Photopicker1" runat="server" ImageId='<%# Bind("photo") %>' />
or
ImageFetch.ashx in output.Write(d, 0, d.Length);
I don't remember for sure anymore.
I modified the DeleteCommand for both image and album on PhotoAlbum_Contents.aspx:
DeleteCommand="DELETE FROM Albums WHERE (albumid = @albumid); UPDATE Announcements SET Photo=0 WHERE (albumid = @albumid); UPDATE Events SET Photo=0 WHERE (album = @albumid); UPDATE Announcements SET albumid=Null WHERE (albumid = @albumid); UPDATE Events SET album=Null WHERE (album = @albumid);"DeleteCommand="DELETE FROM images WHERE (id = @id); UPDATE Announcements SET photo=0 WHERE (photo = @id); UPDATE Events SET photo=0 WHERE (photo = @id)"Setting Photo columns to 0 and the album columns to null resovled the issues I had.
Now, if I delete an image or album that I used on a news/event item, I don't have any issues. the items simply appear without an image as expected.
thanks,
gary
xlr8u2
Member
2 Points
1 Post
Re: Deleting a Photo Album
Apr 11, 2010 04:17 AM|LINK
hi i am verrry new to c#.net so if this answer sound stupid, sorry. i am running the club site and wanted to delete the photo album too, so i just commented out the link to it in the site map and left it in without a way to get to it. i don't know if this is the right way to do it but it does work. hope it helps
ScottV.
Member
50 Points
15 Posts
Re: Deleting a Photo Album
Aug 25, 2010 08:37 AM|LINK
The easiest way to handle this is to put a DELETE TRIGGER on the Albums table that'll cascade the delete to all the corresponding images in the Photos table. As for the missing photos issue, there is some logic in the Events_List.aspx page (specifically the Repeater) to handle no pictures:
<asp:Repeater ID="rpEvents" runat="server" DataSourceID="sdsEvents">
<ItemTemplate>
<div>
<div>
<a href='<%# "Events_view.aspx?Eventid=" Eval("ID").toString()%>'>
<Club:ImageThumbnail ID="ImageThumbnail1" runat="server" PhotoID='<%# Eval("photo") %>'
NoPhotoImg="images/calendar.jpg" /> <--- image stored in \images on file system
And in the code, make sure you handle/ceck for null values so things don't choke if there's no picture.
Regards,
Scott