tags:

views:

842

answers:

3

Is it normal behavior for an ImageButton event to not fire if it can't find the image for it. For example, assume I have the following piece of code:

imageLink = new ImageButton();
imageLink.ImageUrl = "~/images/arrow.png";

If the page finds arrow.png, the image click works, but if it doesn't find it, it does not work.

These images are created dynamically and a CommandName, CommandArgument and Click Handler are assigned.

void imageLink_Click(object sender, ImageClickEventArgs e)
{
    ImageButton button = (ImageButton)sender;
    Detail oDetail = new Detail();

    switch(button.CommandName)
    {
        case "Band":
             oDetail.Band  = button.CommandArgument;
                break;
            case "State":
                oDetail.State = button.CommandArgument;
                break;
        }                    

        Session["Page2"] = oDetail;

        Response.Redirect("~/Page2.aspx");
    }
A: 

No, that is not normal. I just tested and even if you never set ImageUrl the button will still post back. Are you certain that the issue is not related to event handling?

Andrew Hare
This is my event handler:imageLink.Click += new ImageClickEventHandler(imageLink_Click);
Xaisoft
Can you post more code? I am specifically interested in knowing where you attach the event handler (as in what part of the ASP.NET life-cycle) and what imageLink_Click method looks like.
Andrew Hare
It creates the event in Page_Load. I will post code for the imageLink_Click
Xaisoft
A: 

In some cases, it happens Image button events are not firing sometime without image Anybody know the exact reason behind this issue, please post here

A: 

Hi,

yes, that's right. If the ImageButton doesn't have an ImageUrl declared, it won't fire the onclick event. It will cause a Postback, but the event isn't fired.

This code won't fire the event

<asp:ImageButton ID="testImgBtn" ImageUrl="" runat="server" onclick="testImgBtn_Click" />

while this does:

<asp:ImageButton ID="testImgBtn" ImageUrl="http://www.google.it/intl/en_en/images/logo.gif" runat="server" onclick="testImgBtn_Click" />
Juri