Click to See Complete Forum and Search --> : DataList Image Buttons not working


mcmcom
March 19th, 2006, 05:12 PM
hi all.

i have the following data list and inside it are image buttons that are thumbnails. When clicked they assign another image a value and thats it. It works only once though, then subsequent clicks on the images do nothing, they don't even trigger the event? Whats wrong with this?
thanks!


here is how the data list looks:


<tr>
<td><asp:DataList ID="dlThumbs" Runat="server" RepeatDirection="Horizontal">
<ItemTemplate>
<asp:ImageButton ID="gallery" OnCommand="ImageButton_Command" CommandName="<%# Container.DataItem %>"
CommandArgument="show" ImageUrl="<%# Container.DataItem %>" Runat="server" />
</ItemTemplate>
</asp:DataList>
</td>
</tr>


and here is the event


public void ImageButton_Command(object sender, CommandEventArgs e)
{
string tmpFile = e.CommandName.Substring(0,e.CommandName.Length - 10) + e.CommandName.Substring(e.CommandName.Length - 4);
this.imgLarge.ImageUrl = tmpFile;
this.imgLarge.Visible = true;
this.dlThumbs.SelectedIndex = 0;
}

mcmcom
March 20th, 2006, 12:40 PM
It works again if i press BACKSPACE, then click in the DataList.

I also tried replacing ImageButton with LinkButton and it now notices the click, but gives me some weird error saying "error on page" like its a javascript error.
Could it be that im using an ArrayList for the DataSource and not using Container.eval???

im stumped on this one,
any IDEAS or help IS SO MUCH APPRECIATED, i've posted this message on 10 forums and have gotten NO HELP

mcm

mcmcom
March 20th, 2006, 02:10 PM
well, i solved this one.

I dont know what was wrong originally, but i just re-created the whole page again (good think we're still in pre-design development) and it works fine. The only difference is i didn't even bother with a ImageButton, i just used Linkbutton with a <img> tag in it.

Anyways, some key thoughts:

1) Dont re-bind without looking for !IsPostBack
2) If you can wire the event in codebehind as opposed to "OnItemCommand" in the aspx page then do that.
3) If you follow those two points and it doesn't work, save yourself headaches and re-create the component / page.

hth,
mcm

HairyMonkeyMan
March 21st, 2006, 03:59 AM
Well done solving your problem.

My thoughts are that:
- I would have had "show" as the command name, and the data in the commandargument (probably makes little difference).
- I normally bind my data like this: '<%# Container.DataItem("field_name") %>' (although nice to know we can do it your way - must check that out)

Thanks

mcmcom
March 21st, 2006, 11:05 AM
ya it was a weird problem.

now that i had it fixed i modified the methods to produce a DataSet from the file system instead of an array list, i built an additional column on the fly and now dont have to do any string processing to pull the image because col 0 is the thumb name and col 1 is the larger image name. it works good and is now paged, which is great too.!

mcm