开发者

ImageButton not hitting codebind method, but does if replaced with LinkButton

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$ctl0开发者_开发知识库4$ImageButton_DeleteRun','')"
id="ctl00_ctl00_ctl00_AllContent_MainContent_MainContent_controlPanelQueryHistory_saved_RadGridQueryHistory_ctl00_ctl04_ImageButton_DeleteRun">delete</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>


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


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


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜