EventHandler is null

早过忘川 提交于 2019-12-04 02:37:19

The code looks simple enough to work correctly. The only reason that btnHandler is null could be because the event registration code in the aspx page is not called.

Is there a post back ? Are you sure you are adding the event EACH TIME the page loads ???

ucStepHdr.btnHandler += new StepsHeader.OnImageButtonClick(ucStepHdr_btnHandler);

If you remove OnClick="imgstep1_Click" and you put this in your ascx.cs

protected ImageButton imgstep1;

protected override void OnInit(EventArgs e)
{
    this.imgstep1.Click += new ImageClickEventHandler(imgstep1_Click);
}

Does this method of wiring up your event work?

It looks like it should work... can you step through the code in the debugger, and see what the value of ucStepHdr.btnHandler is as soon as you set it in Page_Load? (Just an aside, traditionally these are set in init rather than load, but this isn't your issue.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!