单击事件不会触发

单击事件不会触发

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

问题描述

嗨朋友们,



我在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

推荐答案

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



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");
        }





请检查以下链接:

[]



希望这可能会有所帮助。



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

Hope this may help.


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

08-02 02:04