imagebutton clicking issues

V

vortigern79

Hello,

I'm currently writing a webpage that lists photos dynamically.
Depending on what was selected in the page previous, these photos will
change. What I'd like to do it to have the user click on a photo and
for that to pull up another page associated with that photo. I can't
figure out how to make this happen, however. Here's my html referring
to the imagebutton:

<asp:DataList ID="DataList1" runat="server">
<AlternatingItemStyle BackColor="#FFFFCC"></AlternatingItemStyle>
<ItemStyle BackColor="White"></ItemStyle>
<ItemTemplate>
<table border="0" cellpadding="2" cellspacing="0" class="Normal">
<tr>
<td>
<asp:Imagebutton ID="imgPhotoGallery" ImageUrl='<%#
Container.DataItem %>' Runat="Server" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>

And I can't seem to get this to attach to any function in the
corresponding .aspx file.

I initially thought it would be this function:

Protected Sub DataList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DataList1.SelectedIndexChanged
Dim sRedirect As String

'go to edit page
sRedirect = "Photo_Edit.aspx"
Server.Transfer(sRedirect)
End Sub

But that doesn't seem to work.

Please help!
 
F

fd123456

Hi vortiger,

You should add a handler to a method inside the ImageButton code this
way :

<asp:Imagebutton
ID="imgPhotoGallery"
ImageUrl='<%# Container.DataItem %>'
Runat="Server"
OnClick="imgPhotoGallery_Click" />

Then create the corresponding method :

protected void imgPhotoGallery_Click(object sender,
ImageClickEventArgs e)
{
// Handle the redirect / transfer here
}

You also have the option to replace your ImageButton with a simple
link containing an image, and embed the destination url directly into
the link :

// datalist definition...
<td>
<a href="<%# RedirectAddress %>">
<asp:Image
ID="Image1"
runat="server"
ImageUrl='<%# Container.DataItem %>'/>
</a>
</td>
// datalist definition...

You could set RedirectAddress through a column in your data source,
for instance. This solution avoids the round-trip to the server. Of
course, this is only possible if redirecting is the only thing your
button does.

HTH,

Michel
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top