473,386 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Thumbnail control does not update after images added/removed.

RB
Hi there,

I'm having a problem with an ASP.NET/VB.NET Control I am writing.

The control is a simple gallery control, which shows a set of thumbnails
(using a DataList), and a main image of the selected thumbnail. It also
has "Add Picture" and "Delete Picture" buttons.
"Add Picture" will add a new picture, while "Delete Picture" will remove
the currently selected picture. These are both ASP:ImageButtons, with
the functionality implemented in the OnClick events.

This control is then embedded in a page. This all works, with only 1
problem.

When I add a new picture it does not appear until I manually reload the
page. Conversely, when I delete a picture it leaves a blank picture in
place (the file itself has been deleted, so I get the missing image
'X'), until I manually reload the page.

I'm an experienced programmer, but I'm new to ASP .NET, so please take
that into account ;-)

Regards,

RB.

CODE SNIPPETS:
' ASCX PAGE
<div id="dvToolbar" class="toolbar">
File:
<INPUT
id="MyFile"
type="file"
size="40"
name="MyFile"
RunAt="Server"
/>
<br>
Caption:
<asp:textbox id="txtCaption"
runat="server"
EnableViewState="False">
</asp:textbox>
<asp:imagebutton id="btnAddPicture"
Runat="server"
ImageUrl="\image\add_.gif"
AlternateText="Add new picture"
EnableViewState="False">
</asp:imagebutton>
<asp:imagebutton id="btnDeletePicture"
Runat="server"
ImageUrl="\image\del_.gif"
AlternateText="Remove current picture"
EnableViewState="False">
</asp:imagebutton>
<asp:imagebutton id="btnEditCaption"
Runat="server"
ImageUrl="\GEMs\image\Edit.gif"
AlternateText="Set caption of current picture"
EnableViewState="False">
</asp:imagebutton>
</div>
<div id="dvPhotos" runat="server">
<div id="dvThumbnails" class="thumbnails">
<asp:datalist id="dlPhotos"
RepeatDirection="Horizontal"
runat="server"
RepeatLayout="Flow"
Height="18px"
EnableViewState="False">
<ItemTemplate>
<asp:Image ID="Image1"
Runat=server ImageUrl='<%# "Thumbnail.aspx?filename=" &
Container.DataItem("photoFileName") & "&width=120" %>'
AlternateText='<%# Container.DataItem("photoDescription")%>'>
</asp:Image>
</ItemTemplate>
</asp:datalist>
</div>
<div id="dvMain" class="mainimage">
<asp:image id="imgMain"
runat="server"
EnableViewState="False">
</asp:image>
<br />
<div style="VISIBILITY:hidden">
<asp:TextBox id="txtHiddenPhotoId" Runat="server" />
</div>
</div>
</div>

' CODE BEHIND
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' Bind thumbnail images to grid
Dim sr As SqlClient.SqlDataReader = myDev.GetDevPhotos(DevId)
If (sr.Read) Then
ShowPhotoControls(True)
Else
ShowPhotoControls(False)
End If
dlDevelopmentPhotos.DataSource = myDev.GetDevPhotos(DevId)
dlDevelopmentPhotos.DataBind()
End Sub

Private Sub ShowPhotoControls(ByVal bShow As Boolean)
'Hide the photos div block (dvPhotos) and the
'Delete button if required (because there are no
'photos available).
If bShow Then
dvPhotos.Attributes.Item("style") = ""
Else
dvPhotos.Attributes.Item("style") = "VISIBILITY:hidden"
End If
btnDeletePicture.Visible = bShow
End Sub

Private Sub btnDeletePicture_Click(ByVal sender As System.Object,
ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnDeletePicture.Click
'Code to remove picture from database
End Sub

Private Sub btnAddPicture_Click(ByVal sender As System.Object,
ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnDeletePicture.Click
'Code to save uploaded picture.
'Code to insert photo into database.
End Sub
Aug 29 '07 #1
2 1899
Your code to show the photos may be happening before the photo is being
added. In this case, you need to force a re-show of the photos. You could
put your photo-showing code into a function so that you can call it again
from your insert and delete functions.
--
Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"RB" <ow************@mailinator.comwrote in message
news:aL******************************@eclipse.net. uk...
Hi there,

I'm having a problem with an ASP.NET/VB.NET Control I am writing.

The control is a simple gallery control, which shows a set of thumbnails
(using a DataList), and a main image of the selected thumbnail. It also
has "Add Picture" and "Delete Picture" buttons.
"Add Picture" will add a new picture, while "Delete Picture" will remove
the currently selected picture. These are both ASP:ImageButtons, with the
functionality implemented in the OnClick events.

This control is then embedded in a page. This all works, with only 1
problem.

When I add a new picture it does not appear until I manually reload the
page. Conversely, when I delete a picture it leaves a blank picture in
place (the file itself has been deleted, so I get the missing image 'X'),
until I manually reload the page.

I'm an experienced programmer, but I'm new to ASP .NET, so please take
that into account ;-)

Regards,

RB.

CODE SNIPPETS:
' ASCX PAGE
<div id="dvToolbar" class="toolbar">
File:
<INPUT
id="MyFile"
type="file"
size="40"
name="MyFile"
RunAt="Server"
/>
<br>
Caption:
<asp:textbox id="txtCaption"
runat="server"
EnableViewState="False">
</asp:textbox>
<asp:imagebutton id="btnAddPicture"
Runat="server"
ImageUrl="\image\add_.gif"
AlternateText="Add new picture"
EnableViewState="False">
</asp:imagebutton>
<asp:imagebutton id="btnDeletePicture"
Runat="server"
ImageUrl="\image\del_.gif"
AlternateText="Remove current picture"
EnableViewState="False">
</asp:imagebutton>
<asp:imagebutton id="btnEditCaption"
Runat="server"
ImageUrl="\GEMs\image\Edit.gif"
AlternateText="Set caption of current picture"
EnableViewState="False">
</asp:imagebutton>
</div>
<div id="dvPhotos" runat="server">
<div id="dvThumbnails" class="thumbnails">
<asp:datalist id="dlPhotos"
RepeatDirection="Horizontal"
runat="server"
RepeatLayout="Flow"
Height="18px"
EnableViewState="False">
<ItemTemplate>
<asp:Image ID="Image1"
Runat=server ImageUrl='<%# "Thumbnail.aspx?filename=" &
Container.DataItem("photoFileName") & "&width=120" %>'
AlternateText='<%# Container.DataItem("photoDescription")%>'>
</asp:Image>
</ItemTemplate>
</asp:datalist>
</div>
<div id="dvMain" class="mainimage">
<asp:image id="imgMain"
runat="server"
EnableViewState="False">
</asp:image>
<br />
<div style="VISIBILITY:hidden">
<asp:TextBox id="txtHiddenPhotoId" Runat="server" />
</div>
</div>
</div>

' CODE BEHIND
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' Bind thumbnail images to grid
Dim sr As SqlClient.SqlDataReader = myDev.GetDevPhotos(DevId)
If (sr.Read) Then
ShowPhotoControls(True)
Else
ShowPhotoControls(False)
End If
dlDevelopmentPhotos.DataSource = myDev.GetDevPhotos(DevId)
dlDevelopmentPhotos.DataBind()
End Sub

Private Sub ShowPhotoControls(ByVal bShow As Boolean)
'Hide the photos div block (dvPhotos) and the
'Delete button if required (because there are no
'photos available).
If bShow Then
dvPhotos.Attributes.Item("style") = ""
Else
dvPhotos.Attributes.Item("style") = "VISIBILITY:hidden"
End If
btnDeletePicture.Visible = bShow
End Sub

Private Sub btnDeletePicture_Click(ByVal sender As System.Object,
ByVal e As System.Web.UI.ImageClickEventArgs) Handles
btnDeletePicture.Click
'Code to remove picture from database
End Sub

Private Sub btnAddPicture_Click(ByVal sender As System.Object, ByVal e
As System.Web.UI.ImageClickEventArgs) Handles btnDeletePicture.Click
'Code to save uploaded picture.
'Code to insert photo into database.
End Sub

Aug 29 '07 #2
RB
Mark Fitzpatrick wrote:
Your code to show the photos may be happening before the photo is being
added. In this case, you need to force a re-show of the photos. You could
put your photo-showing code into a function so that you can call it again
from your insert and delete functions.

I did as you suggest and called dlDevelopmentPhotos.DataBind from the
Add and Delete functions, and it worked a treat (it was already in a
function, I just took it out while posting to the newsgroup for
clarity!!), so thank-you a huge amount for that :-)

I do have one question though - why did it not work as it was?

Consider this code:
<script runat="server">
Sub Page_Load
If Not Page.IsPostBack Then
lbl1.Text="The First Load was at " & now()
End If
lbl2.Text="The Current Load was at " & now()
End Sub

Sub Submit(s As Object, e As EventArgs)
End Sub
</script>

<html>
<body>
<form runat="server">
<h3><asp:label id="lbl1" runat="server" /></h3>
<h3><asp:label id="lbl2" runat="server" /></h3>
<h3><asp:label id="lbl3" runat="server" /></h3>
<asp:button text="Submit" onclick="submit" runat="server" />
</form>
</body>
</html>

When you load this the first time, lbl1 and lbl2 will have the same
time. Clicking submit will cause lbl2's time to be updated, while
refreshing the page will cause both labels to be updated. This makes
sense to me.

Changing it to be my code, and considering "lbl2.text=" to be
dlDevelopmentPhotos.Bind, it should work (in my feeble little mind at
least!!), but instead it was behaving like lbl1 would. I checked whether
the containing page had a "Not Page.IsPostBack" line in it, but it didn't.

Obviously I'm missing something vital here - I was just wondering if any
one could shed a little light on it!

Many thanks,

RB.
Aug 29 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Stevie D | last post by:
Hi I'm a Javascript newbie I'm doing a 'simple' (basically adding pages and changing text in frontpage 2000) update of a web site for a friend - what I have done 'should not' have done anything...
1
by: Kanaiya | last post by:
hello i want to show thumbnail image view control which display captured images on this control but in small size. it is possible to add any no. of images in that control. and aslo possible to add...
2
by: David Elliott | last post by:
I am creating a control to display GIF/JPEG images for my website. The control has a Panel to hold the images. I would like to perform the following. 1) store the original on disk and create a...
11
by: Jane | last post by:
Hi, I need some help (php rookie) to build a thumbnail page using php. I'v a mysql database containing links to the original image files. No thumbnails created so far. It would be nice when...
3
by: lolo | last post by:
hello. happy new year. I'm trying to build a website for my wife and she is adament on having a horizontal thumbnail scrolling div. great. I have a good vertical scrolling thing, but can't...
7
by: oscartheduck | last post by:
Hi folks, I'm trying to alter a program I posted about a few days ago. It creates thumbnail images from master images. Nice and simple. To make sure I can match all variations in spelling of...
8
by: Arno R | last post by:
Hi all. When I need to search for pictures, I always have too choose thumbnail-view manually. Is it possible to open the common dialog in thumbnail-view programmatically? Example ?? At the...
7
by: flamer die.spam | last post by:
Hi all, I have a new website im setting up, its a large image archive, I have it setup to open a folder, go through and for each file in that folder check a /tn sub-folder for a matching name, if...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.