简体   繁体   English

事件不触发?

[英]Event does not fire?

I want to create an imagebutton in code behind like this: 我想在背后的代码中创建一个imagebutton,如下所示:

ImageButton img1 = new ImageButton();
img1.CssClass = "stylImage";
img1.ImageUrl = @"~/images/Workflow/esign.jpg";
img1.AlternateText = "Signature";
img1.CommandName = "edit";
img1.Click += new ImageClickEventHandler(Image_OnClientClick);
img1.Command += new CommandEventHandler(Image_OnCommand);
workdesk.Controls.Add(img1);

The button create and display on page, but none of the click or command event fire. 该按钮将创建并显示在页面上,但不会触发click或command事件。
There is no error or exception too. 也没有错误或异常。

Any ideas?!? 有任何想法吗?!?

Your code works fine and both the events fires perfectly as I tested. 您的代码运行良好,并且正如我测试的那样,两个事件均能完美触发。

There may be a chance that you have not specified the Event Definition correctly. 您可能没有正确指定Event Definition

Please recheck the below code which works like a charme..!! 请重新检查下面的代码,它看起来像个迷笛.. !!

protected void Page_Load(object sender, EventArgs e)
{
    ImageButton img1 = new ImageButton();
    img1.CssClass = "stylImage";
    img1.ImageUrl = @"~/images/Workflow/esign.jpg";
    img1.AlternateText = "Signature";
    img1.CommandName = "edit";
    img1.Click += new ImageClickEventHandler(Image_OnClientClick);
    img1.Command += new CommandEventHandler(Image_OnCommand);
    form1.Controls.Add(img1);

}

protected void Image_OnClientClick(object sender, ImageClickEventArgs e)
{
    //some code...
}

protected void Image_OnCommand(object sender, CommandEventArgs e)
{
    //some code...
}

This may help you..!! 这可以帮助您.. !!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM