views:

34

answers:

1

hi,

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. 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.

A: 

Ah!! I found the solution to my problem.

in the function CreateChildControls() we should also add the controls to the control collection. once i did that the code worked just fine.

thanks

Shrewd Demon