图像按钮链接按钮单击事件工作时,单击事件不会触发 [英] Image button Click event is not fire while Link button click event is working

查看:79
本文介绍了图像按钮链接按钮单击事件工作时,单击事件不会触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我在visual studio 2008中有一个web应用程序,使用和Image按钮保存我的详细信息,



< asp:ImageButton ID =imgSaverunat =serverImageUrl =〜/ images / save.pngonclick =imgSave_Click/>



但问题是上面按钮的点击事件不火了



Hi Friends,

I have a web application in visual studio 2008 and using and Image button to save my details,

<asp:ImageButton ID="imgSave" runat="server" ImageUrl="~/images/save.png" onclick="imgSave_Click" />

But the problem is that click event of above button is not fire

protected void imgSave_Click(object sender, ImageClickEventArgs e)
   {
       //save code
   }





但是我在同一页面上使用链接按钮



< asp:LinkBut​​ton ID = lnkSaverunat =serverOnClick =lnkSave_Click>< img src =〜/ images / save.png/>





But While m using a link button on the same page

<asp:LinkButton ID="lnkSave" runat="server" OnClick="lnkSave_Click"><img src="~/images/save.png" />

protected void lnkSave_Click(object sender, EventArgs e)
   {
       //save code
   }





工作正常我。我没有得到图像按钮的问题。



提前谢谢

Parveen Rathi



it is working fine for me. I am not getting what is the issue with image button.

Thanks in advance
Parveen Rathi

推荐答案

试过这个..?



从后面的代码中添加图像按钮的事件处理程序。



Tried this..?

Add event handler for image button from code behind.

override protected void OnInit(EventArgs e)
        {
           this.imgSave.Click += 
               new System.Web.UI.ImageClickEventHandler(this.imgSave_Click);
            base.OnInit(e);
        }


我找到了一些有用的链接。检查一下。



asp:ImageButton未触发onclick事件



图像按钮onclick事件未被触发



asp.net Button OnClick事件没有触发
I have found some useful links for you.Check that.

asp:ImageButton not firing onclick event

image button onclick event not fired

asp.net Button OnClick event not firing


这是页面生命周期问题。



您正在将ImageButton添加到页面中(并且在PreRender阶段期间注册您的处理程序,这发生在调度控制事件之后。因此,永远不会调用您的处理程序。



尝试在加载阶段添加按钮,如果可能的话。

This is a page lifecycle problem.

You're adding the ImageButton to the page (and registering your handler) during the PreRender phase, which occurs after control events have been dispatched. Therefore, your handler will never be called.

Try adding the button during the Load phase, if at all possible.
protected void Page_Init(object sender, EventArgs e)
    {
        ImageButton imgButton;

        imgButton = new ImageButton();

        imgButton.ID = "prgcode";
        imgButton.ImageUrl = "~/images/2.jpg";
        imgButton.ToolTip = "test";

        imgButton.Click += new ImageClickEventHandler(imgButton_click);
        Page.Form.Controls.Add(imgButton);

    }
        private void imgButton_click(object sender, ImageClickEventArgs e)

        {
            Response.Write("adfa");
        }





请检查以下链接:

http://www.aspsnippets.com/Articles/Creating-Dynamic-Button-LinkBut​​ton- and-ImageButton-in-ASP.Net.aspx [ ^ ]



希望这可能会有所帮助。



Please check the following link:
http://www.aspsnippets.com/Articles/Creating-Dynamic-Button-LinkButton-and-ImageButton-in-ASP.Net.aspx[^]

Hope this may help.


这篇关于图像按钮链接按钮单击事件工作时,单击事件不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆