Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2008 > C# 2008 aka C# 3.0
|
C# 2008 aka C# 3.0 Discuss the Visual C# 2008 (aka C# 3.0) language
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2008 aka C# 3.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 26th, 2008, 05:51 AM
Authorized User
 
Join Date: Aug 2008
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problems with Image Handler Click Event

Hei there ... I have a dynamic ImageButton witch I use for loading thumbnails, and I want when I click on them to open the large image. I use ImageClickEventHandler like this:
System.Web.UI.WebControls.ImageButton newImage = new ImageButton();

newImage.ImageURL = server_address;

newImage.Click += new System.Web.UI.ImageClickEventHandler(newImage_Clic k);

protected void newImage_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            GetLargeImage();
        }

And nothing happens. I use the debug to and still nothing. I use Asp .net 3.5 with C# 3.0 in VS2008 and I have my large image in an asp:Image component witch is in a table component and all in the ajax component UpdatePanel.

 
Old August 26th, 2008, 05:56 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You need to set the ID property of any programatically created buttons you create so that the code knows which button to hook up the event for.

/- Sam Judson : Wrox Technical Editor -/
 
Old August 27th, 2008, 01:34 AM
Authorized User
 
Join Date: Aug 2008
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

And how do I do that?
I don't know how many thumbnails I receive from the server, and I need to create my buttons instantly.
Thank you.

 
Old August 27th, 2008, 02:34 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The ID can be anything that uniquely identifies the control - you might use some aspect of "server_address" (such as a unique filename, or query string element) but I don't know what that is, so can't help you more.

/- Sam Judson : Wrox Technical Editor -/
 
Old August 27th, 2008, 04:03 AM
Authorized User
 
Join Date: Aug 2008
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The problem is that my ImageButton doesn't open anything. the server_address is has a string witch indicates the thumbnail for the server to know.
And my thumbnails are visible but when I click nothing happens. That is my big problem.
Thank you and sorry for not understanding you.

 
Old August 27th, 2008, 04:10 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

If for example server_address is a string like so "image\image27.jpg", which points to an image on your server, then assuming that each ImageButton has a unique image you could do the following:

Code:
System.Web.UI.WebControls.ImageButton newImage = new ImageButton();
newImage.ImageURL = server_address;
newImage.ID = "imageButton" + Path.GetFileNameWithoutExtension(server_address);
newImage.Click += new System.Web.UI.ImageClickEventHandler(newImage_Click);
The other thing you then need to do is ensure that in the postback event this button is recreated with the same ID.

/- Sam Judson : Wrox Technical Editor -/
 
Old August 27th, 2008, 05:30 AM
Authorized User
 
Join Date: Aug 2008
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Still nothing. This is my code:
private void AddThumb()
{
System.Web.UI.WebControls.ImageButton newImage = new ImageButton();
      newImage.Style.Add(HtmlTextWriterStyle.Margin, "10px");
      newImage.Style.Add(HtmlTextWriterStyle.BorderColor , "#660066");
      newImage.Style.Add(HtmlTextWriterStyle.BorderStyle , "Solid");
      newImage.Style.Add(HtmlTextWriterStyle.BorderWidth , "1px");
      newImage.AlternateText = myId;
      newImage.ImageUrl = "http://192.168.1.66/bigview/bigviewserver.dll?sessid=" + sessionID + "&thumb=" + myId + ".jpg";
            try
            {
                myThumbPanel.Controls.Add(newImage);
            }
            catch (Exception ex)
            { }
      newImage.ID ="imageButton" + Path.GetFileNameWithoutExtension("http://192.168.1.66/bigview/bigviewserver.dll?sessid=" + sessionID + "&thumb=" + myId);
      newImage.Click += new System.Web.UI.ImageClickEventHandler(newImage_Clic k);
}

        protected void newImage_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            Details();
        }

I have a loading bar and when I click on the button is shows something but it does not open the image.
Thank you.

 
Old August 27th, 2008, 05:37 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The following will probably be enough:

newImage.ID ="imageButton" + myId

Now you just need to make sure you are recreating the thumbnail in the Page_Init event.

/- Sam Judson : Wrox Technical Editor -/
 
Old August 27th, 2008, 06:24 AM
Authorized User
 
Join Date: Aug 2008
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What do you mean by recreating the thumbnail in the Page_Init event?

 
Old August 27th, 2008, 07:15 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The following web page describes how to create dynamic controls, and how to wire events up to them. The creation of the dynamic web controls should be placed in the Page_Init event handler.

http://support.microsoft.com/kb/317515

This ensures that when you click the ImageButton and the page is recreated, the ImageButton is recreated, and provided it has the same ID each time the events will be handled correctly.

/- Sam Judson : Wrox Technical Editor -/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Mouse Event Handler daniel.mihalcea C# 2008 aka C# 3.0 1 September 8th, 2008 06:30 AM
Mark a point in Image and handle click event on it savan_thakkar ASP.NET 1.0 and 1.1 Professional 3 June 9th, 2006 02:56 AM
Event handler samir_katore Pro VB 6 6 June 8th, 2006 01:22 PM
chapter 8, click event handler krothenb BOOK: Beginning Access VBA 1 June 30th, 2004 03:02 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.