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)?
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.
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.
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.
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
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)
{
//.......
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With