Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

imagebutton clicking issues

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
vortigern79@yahoo.com - 02 Aug 2007 21:35 GMT
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!
fd123456@hotmail.com - 04 Aug 2007 13:22 GMT
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

On 2 ao?t, 22:35, vortiger...@yahoo.com wrote:
> Hello,
>
[quoted text clipped - 37 lines]
>
> Please help!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.