 |
| 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
|
|
|
|

August 26th, 2008, 05:51 AM
|
|
Authorized User
|
|
Join Date: Aug 2008
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

August 26th, 2008, 05:56 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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 -/
|
|

August 27th, 2008, 01:34 AM
|
|
Authorized User
|
|
Join Date: Aug 2008
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

August 27th, 2008, 02:34 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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 -/
|
|

August 27th, 2008, 04:03 AM
|
|
Authorized User
|
|
Join Date: Aug 2008
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

August 27th, 2008, 04:10 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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 -/
|
|

August 27th, 2008, 05:30 AM
|
|
Authorized User
|
|
Join Date: Aug 2008
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

August 27th, 2008, 05:37 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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 -/
|
|

August 27th, 2008, 06:24 AM
|
|
Authorized User
|
|
Join Date: Aug 2008
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
What do you mean by recreating the thumbnail in the Page_Init event?
|
|

August 27th, 2008, 07:15 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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 -/
|
|
 |