简体   繁体   English

事件不会在自定义控件中触发

[英]Event wont fire in custom control

I am trying to create a simple custom control where in there is a image button on the control along with a label. 我试图创建一个简单的自定义控件,其中控件上有一个图像按钮以及一个标签。

the problem that i am facing is that the image button appears just fine along with the specified properties. 我面临的问题是图像按钮与指定的属性一起显示得很好。 But somehow when i click on the image button it does not generate the click event. 但是以某种方式,当我单击图像按钮时,它不会生成click事件。 the page simply refreshes. 该页面只是刷新。

Can some one please tell me what is the mistake ??? 有人可以告诉我这是什么错误吗?

public override ControlCollection Controls
{
    get
    {
        EnsureChildControls();
        return base.Controls;
    }
}

protected override void RenderContents(HtmlTextWriter output)
{
    //CreateChildControls();
    AssociateValuesWithProperties();

    ibFirst.RenderControl(output);
    output.RenderEndTag();
}

protected override void CreateChildControls()
{
    Controls.Clear();

    // Set subcontrols behavior
    //adding the event handlers to the image buttons
    ibFirst.Click += new ImageClickEventHandler(ibFirst_Click);
}

private void AssociateValuesWithProperties()
{
    ibFirst.ImageUrl = FirstImageSrcNormal;
    ibFirst.AlternateText = FirstImageAltText;
    ibFirst.ToolTip = FirstImageAltText;
}

protected void ibNext_Click(object sender, ImageClickEventArgs e)
{
    this.CurrentPage++;
}

Thank you. 谢谢。

Ah!! 啊!! I found the solution to my problem. 我找到了解决我问题的方法。

in the function CreateChildControls() we should also add the controls to the control collection. 在函数CreateChildControls()中,我们还应该将控件添加到控件集合中。 once i did that the code worked just fine. 一旦我这样做,代码就可以正常工作。

thanks 谢谢

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

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