473,403 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

ImageButton.Click Event calling a method

I am assigning a dynamic imagebutton on a page and then assiging it a Click
event with the following code, to pass the string "test" to the DeleteDetail
method

testImgBtn.ID = "imgBtn" + loopnumber;
testImgBtn.ImageUrl = "imgs/delete_16.gif";
testImgBtn.AlternateText = "Delete this detail";
testImgBtn.Style["background-color"] = "#B4B4B4";
testImgBtn.Click += new ImageClickEventHandler(DeleteDetail("test"));

The method very simply is

protected void DeleteDetail(string id)
{
Response.Write(id);
}

However when i try to compile this, i get "Method name expected" error on
the Click line in the original code

Can anyone help with this one?

--
Mark
Dec 7 '05 #1
2 4274
The .Click property expects the name of the method not an actual call
to the method

the click event handler has to take the form of: -

private void ImageButton1_Click(object sender,
System.Web.UI.ImageClickEventArgs e)

in your button creation code add this: -

testImgBtn.CommandArgument = "test";

then in the event hander method you can do this: -

ImageButton b = (ImageButton)sender;
string value = b.CommandArgument;
//value will equal "test"

Dec 7 '05 #2
Gareth

Thank you very much for that, it was really annoying me! :)

--
Mark
"ga**********@gmail.com" wrote:
The .Click property expects the name of the method not an actual call
to the method

the click event handler has to take the form of: -

private void ImageButton1_Click(object sender,
System.Web.UI.ImageClickEventArgs e)

in your button creation code add this: -

testImgBtn.CommandArgument = "test";

then in the event hander method you can do this: -

ImageButton b = (ImageButton)sender;
string value = b.CommandArgument;
//value will equal "test"

Dec 7 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: JMcD | last post by:
Hi I have a DataGrid with an ImageButton column. When I click on an imagebutton I get a postback but it doesn't run the OnImgBtnClick method. I can actually comment out the line where I add this...
5
by: J McD | last post by:
Hi I have a DataGrid with an ImageButton column. When I click on an imagebutton I get a postback but it doesn't run the OnImgBtnClick method. I can actually comment out the line where I add this...
1
by: Henke | last post by:
Hello, I have one ImageButton controls which I initialize in Page_Load and declare on class level. ImageButton save = new ImageButton(); save.ImageUrl = "save.gif" save.Click += new...
6
by: ruca | last post by:
Hi gurus, I have a imagebutton in my WebForm, and I want that when I click (mouse down) on her the imagebutton change image and when I "unclick" (mouse up) change to the original image. Basically...
3
by: tshad | last post by:
I was trying to change my asp:button to asp:ImageButton, but got a message saying that ImageButton does not have an onClick function. How do I get the ImageButton call a function? Thanks, ...
13
by: tperri | last post by:
I have an HTML table with several fields like this: <A href="Savings.aspx?category=Food"><asp:imagebutton id="imgFood" ImageUrl="images\buttons\btn-food-i.gif"...
3
by: jens.buchta | last post by:
Hi! I'm using a DataGrid with a template column to display an Image inside of it. I'm hooking into its OnPrerender-Event to set the ImageURL-Property dynamically. Everything works just fine...
2
by: Steve | last post by:
Hi, I have a dynamically created ImageButton in a custom control, and I can't get the control to handle the ImageButton Click event. I see the control in the Page.Request.Form.AllKeys collection,...
2
by: dperren | last post by:
At current, I have a set of dynamically generated image buttons, which are created with this (excert) of code: TableCell tasks = new TableCell(); while (reader.Read()) { ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.