views:

189

answers:

6

I have an ImageButton being build inside of radgridview columnn. It is defined as follows.

<asp:ImageButton ID="ImageButton_DeleteRun" ImageUrl="~/Assets/Images/Misc/delete.png"
runat="server" OnClick="QueryDelete" CommandName="QueryDelete" 
CommandArgument='<%# DataBinder.Eval(Container,"DataItem.QueryGuid") %>'
Width="10" Height="10" />

It loads properly. When I click on it, I expect to hit the following codebehind method:

protected void QueryDelete(object sender, EventArgs e)
{
/* A bunch of code*/
}

It never gets there. What is more fustrating is that if I replace the ImageButton with

<asp:LinkButton ID="ImageButton_DeleteRun" Text="X"
runat="server" OnClick="QueryDelete" CommandName="QueryDelete" 
CommandArgument='<%# DataBinder.Eval(Container,"DataItem.QueryGuid") %>'/>

It works perfectly. Is there something wrong with ImageButton? Am I missing something?

EDIT - New info

Basically when the image button is rendered, there is no href.

Weird--

<input type="image" style="height: 10px; width: 10px; border-width: 0px;" src="../Assets/Images/Misc/delete.jpg"
id="ctl00_ctl00_ctl00_AllContent_MainContent_MainContent_controlPanelQueryHistory_saved_RadGridQueryHistory_ctl00_ctl04_ImageButton1"
name="ctl00$ctl00$ctl00$AllContent$MainContent$MainContent$controlPanelQueryHistory_saved$RadGridQueryHistory$ctl00$ctl04$ImageButton1"/>

<a
href="javascript:__doPostBack('ctl00$ctl00$ctl00$AllContent$MainContent$MainContent$controlPanelQueryHistory_saved$RadGridQueryHistory$ctl00$ctl04$ImageButton_DeleteRun','')"
id="ctl00_ctl00_ctl00_AllContent_MainContent_MainContent_controlPanelQueryHistory_saved_RadGridQueryHistory_ctl00_ctl04_ImageButton_DeleteRun">delete</a>
A: 

Maybe the page is validating? If so, try adding CausesValidation=false to the ImageButton.

IrishChieftain
Just tried it, no luck :-(
Matt
A: 

You may want to try replacing OnClick with OnCommand to see if that solves the problem.

mkedobbs
I think this is the answer, it expects a certain handler.
IrishChieftain
This isn't the solution. Using OnClick just means the the CommandArgument that is being set won't be send to the event handler and is thus pointless.
AverageAdam
No go either -- I think I'll just have to stick with a LinkButton for now :-(
Matt
Change the name of the handler to something else that's not the same as the command argument name, just to rule it out...
IrishChieftain
A: 

Silly question - but is the ImageUrl rendering a valid image or red-x?

zincorp
It is a valid image, that was the first thing I checked as I know ImageURL must at the very least be specified.
Matt
Tried using something other than a PNG?
zincorp
Just tried it with a JPG -- problem remains :-(
Matt
A: 

Put both link types in the page and then "View Source" on the resulting page. This may give you some clues as to what is happening. It may be rendering the ImageButton in a way that JavaScript or CSS is messing up.

AverageAdam
A: 

How do you get the command arguments in OnClick? You have an EventArgs. The OnCommand handler has CommandEventArgs containing the CommandName and CommandArguments:

protected void image_Command(object sender, CommandEventArgs e)
{
}

It would make sense to use the OnCommand.

vladhorby
+4  A: 

As a work around you could try wrapping an image within a LinkButton.

<asp:LinkButton ID="ImageButton_DeleteRun" Text="X"
runat="server" OnClick="QueryDelete" CommandName="QueryDelete" 
CommandArgument='<%# DataBinder.Eval(Container,"DataItem.QueryGuid") %>'>
    <img src="~/Assets/Images/Misc/delete.png" /> 
</asp:LinkButton>
Phaedrus