I am building a web site for a friend who is a graphic designer.
He wants to display one image at a time on his home page and have this image selected by clicking on one of a related group of thumbnails.
I have an <aspanel id="ThumbnailList"... > hard coded in the page markup and I'm creating ImageButton instances within my C# code behind from the rows in a DataTable.
Getting the group of ImageButton's to appear on the page is working, but when I click on them I can't get any life out of my ThumbnailClick(object sender, ImageClickEventArgs e) event handler.
The code goes a little something like this...
private const string THUMBNAIL_KEYS = "THUMBNAIL_KEYS";
private List<string> sessionThumbKeys;
[INDENT] var queryInfoArgs = "...";
DataTable dt = FetchDataTable(queryInfoArgs)
foreach(DataRow r in dt.Rows)
[INDENT] string fileID = r["fileID"];
string imageName = r["name"];
string imageURL = r["url"];
ImageButton imageButton = CreateNewThumbnail(fileID,imageName,imageURL);
string sessionKey = "ImageButton_" + fileID;
Session.Add(THUMBNAIL_KEYS, sessionThumbKeys); [/INDENT]
protected ImageButton CreateNewThumbnail(string fileID, string name, string uRL)
[INDENT] ImageButton imageButton = new ImageButton();
imageButton.ID = "ImageButton_" + fileID;
imageButton.ToolTip = name;
imageButton.ImageUrl = uRL;
// Information about the file selected to be sent back when clicked
imageButton.Click += new ImageClickEventHandler(ThumbnailClick);
// Click wasn't working so I added the following
protected void ThumbnailClick(object sender, ImageClickEventArgs e)
[INDENT] .... retrieve fileID, query dataBase for url and set up the full version of the image on the page[/INDENT]
Because the ImageButtons are not in the markup and don't get added when the Page constructor runs I have to bring them back out of session. Since it's all a bit new to me, I'm not 100% sure I'm doing this at the right point in the page lifecycle.
protected override void OnPreLoad(EventArgs e)
[INDENT] if (Session[THUMBNAIL_KEYS] != null)
[INDENT] foreach (string s in (List<string>)Session[THUMBNAIL_KEYS])
[INDENT] if (Session
ImageButton i = (ImageButton)Session
This loads them back into the page nicely but the event doesn't fire.
I initially only set the Click property on the ImageButtons, then I thought about the fact that the ImageButtons get placed into session before they are rendered, so when pulling them out of Session again it's as if they had never been clicked.
So I then added the OnClientClick string, I can get the Request.Form["EVENTTARGET"] and Request.Form["EVENTARGUMENT"] information back nicely at page load and display it on a couple of labels.
I've started to look at Page methods such as RaisePostBackEvent() and RegisterRequiresRaiseEvent()
e.g. during the OnPreLoad foreach...
[FONT="Courier New"]foreach (string s in Session[THUMBNAIL_KEYS...
[INDENT]ImageButton i = Session
if(i.UniqueID == Request.Form["__EVENTTARGET"])
but no joy so far.
I'd really appreciate some pointers!
Can anyone help? If you can I'll run straight out on Tuesday morning and buy you a cut price Easter Egg!