Photo Gallery with next and previous buttons

M

msnews

Hi All,

My client has following request. I am not sure how to do it.

Dynamically from database, we are getting set of images names. Now we want
to display them with next and previous buttons.
I am able to pull all the information from database and put it in javascript
array. Now using two functions for next and previous button, I am able to
browse through the images.

The problem is, when I click on next and previous, it's not hitting the
server (as the information is available at the client). But we want it to
connect it to the server so that the page gets refreshed with new paid ads.

Is it possible to acheive that without hitting the database. Please help me.
It's very urgent.


Thanks,
Anil
 
G

garethdjames

OK, you have got a few options here,

Postback to the server with each click of next or previous, the image
names and text can be stored in the session, or viewstate for better
scalability.

or, do as you are doing now with it all client side, but use an
javascript asynchronous event to reload (or replace) the adverts, the
ajax framework would be a good place to start,

A .Net wrapper for ajax has been release (not open source as yet),

http://ajax.schwarz-interactive.de/csharpsample/default.aspx
 
G

Guest

If you just want to get the ad from the server and not all the stuff on the
page then I'd place the ad in an iframe (If I can force the users to use IE)
and reload the iframe location on button click.
 
M

msnews

Hello Sir,
I tried with viewstate (using arraylist) and it worked. Thanks for that.
But I seem to have some problem. Problem is, even though I am using
viewstate, for every click on next or previous button, it's still trying to
get the data from database. I am using asp:hyperlink for that.

Basically my url for the photo album is as follows
photo.aspx?albumid=20&photoid=6

And my database call and population of viewstate is within
if (!Page.IsPostBack)

Actually, what we are looking for is, whenever the albumid changes then only
refresh the viewstate (get data from database). If only photoid is changing
then use the existing viewstate to link the next, previous links.

Please help me, let me know what mistake i am doing.

Thanks,
Anil.
 
G

garethdjames

The problem that you using an asp:hyperlink, this control does not
cause a post back,

If the page is not a post back (i.e normal load) then load the data
from the DB into an array and store it in the ViewState, then call a
function in the code behind class that renders the appropriate picture,
pass an argument of 0 (zero) to the function, indicating to display the
first picture,

use asp:LinkButton instead of hyperlink, this will cause post back,

create an event handler for each of the LinkButtons (next and
previous), do this by double clicking on the linkbutton, add the
following code (sorry its in c#)

private void NextButton_Click(object sender, System.EventArgs e)
{
int index = (int)ViewState["index"];
index = index + 1;
ViewState["index"] = i;
RenderPicture(index);
}

(where RenderPicture is your function that acts on the viewstate)

also in the RenderPicture function you can disable the next or previous
linkbutton depending if you are at the start or the end of the array,

if you still have trouble zip the code up and mail it to me and I'll
sort it out
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top