Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP ImageButton vs Button

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)?

like image 706
yaegerbomb Avatar asked Nov 22 '11 04:11

yaegerbomb


People also ask

What is an ASP button?

ASP.NET Web Forms Button. This control is used to perform events. It is also used to submit client request to the server. To create Button either we can write code or use the drag and drop facility of visual studio IDE. This is a server side control and asp provides own tag to create it.

What is the use of image button control?

An ImageButton is an AbsoluteLayout which enables you to specify the exact location of its children. This shows a button with an image (instead of text) that can be pressed or clicked by the user.

Which ASP.NET tag creates a link to another browser page?

Use the HyperLink control to create a link to another Web page. The HyperLink control is typically displayed as text specified by the Text property. It can also be displayed as an image specified by the ImageUrl property. If both the Text and ImageUrl properties are set, the ImageUrl property takes precedence.


2 Answers

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

like image 121
Gourav khanna Avatar answered Sep 27 '22 19:09

Gourav khanna


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)
{
    //.......
}
like image 28
rick schott Avatar answered Sep 27 '22 20:09

rick schott