ASP 图像按钮与按钮
我是 ASP.NET 的新手,我对如何解决这个问题感到非常困惑。我已经为所有内容编写了后台代码,现在我只是让所有内容“看起来很漂亮”。最初我有一个 ASP 按钮来提交表单。现在我希望该按钮是 ASP ImageButton。但是现在我的方法由于此更改而返回错误。看起来是这样的:
//.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)
{
;
}
}
将按钮更改为 imagebutton 后生成的错误是:
无法将“System.EventHandler”转换为 'System.Web.UI.ImageClickEventHandler'
所以我的主要问题是:如何修复此错误?这是否会影响我发送到服务器的数据(这会导致与只是一个按钮时不同的行为)?
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)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用以下行
protected void btnSubmit_Click(object sender, ImageClickEventArgs e)
而不是
void btnSubmit_Click(object sender, EventArgs e)
因为图像按钮有不同的事件处理程序..
谢谢
古拉夫
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
的事件签名与Button.OnClick
:ImageButton.OnClick
has a different event signature thanButton.OnClick
:试试这个...
复制以前的方法代码(在btnSubmit_Click中),然后删除整个方法,转到UI(在设计模式下)双击图像按钮&粘贴复制的代码&跑步
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