Question

I am new to asp.net stuff and I am pretty confused on how to fix this problem. I have the back code written for everything and right now I am just making everything "look pretty". Originally I had an ASP button to submit a form for something. Now I want the button to be an ASP ImageButton. However now my method is returning an error due to this change. This is what it looks like:

 //.ascx file
 <div id="eSubmit">
    <asp:ImageButton id="btnSubmit1" runat="server" ImageUrl="~/Style/Images/addButtonE.png" />
</div>


 //method behind
 void btnSubmit_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid) { return; }

        try
        {
            //do some data checking
            //bind entries
        }
        catch (ApplicationException ax)
        {
            ;
        }
    }

The error that is generated after changing the button to imagebutton is:

Cannot convert 'System.EventHandler' to 'System.Web.UI.ImageClickEventHandler'

So my main question is: How do I fix this error? And will this effect the data I am sending to the server in anyway (will this cause different behavior then when it was just a button)?

Was it helpful?

Solution

Use the following line

protected void btnSubmit_Click(object sender, ImageClickEventArgs e)

instead of

void btnSubmit_Click(object sender, EventArgs e)

Because Image button has different event handler .. Thanks Gourav

OTHER TIPS

ImageButton.OnClick has a different event signature than Button.OnClick:

//imagebutton
void btnSubmit_Click(object sender, ImageClickEventArgs e)
{
    //.......
}

//button
void btnSubmit_Click(object sender, EventArgs e)
{
    //.......
}

try this... copy previous method code (in btnSubmit_Click), then delete whole method, go to UI (in design mode) double click the image button & paste the copied code & run

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top