[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

I am Sam

2/16/2008 11:57:00 PM

I need to write a composite control where a click event in the
parent(container) class fires an event in a child control. How is this
possible? ie clicking a button in the parent control performs an action on a
child control.
2 Answers

Teemu Keiski

3/16/2008 4:57:00 PM

0

Hi,

you could access the child control in button's click event? Or if it's
something internal in the child control, it should be informed somehow that
the Click occurred, maybe it could wire up to an event of the parent control
which the parent exposes publicly?

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice....
http://teemu...

"I am Sam" <IamSam@discussions.microsoft.com> wrote in message
news:17145147-092D-46A8-B88D-84344234251F@microsoft.com...
>I need to write a composite control where a click event in the
> parent(container) class fires an event in a child control. How is this
> possible? ie clicking a button in the parent control performs an action
> on a
> child control.


I am Sam

3/16/2008 7:38:00 PM

0

The solution is very simple really. You can for example write the following:
protected override void CreateChildControls()
{
ImageButton someImageButton=new ImageButton();
someImageButton.Click += new ImageClickEventHandler(ImageButton_Click);
this.Controls.Add(someImageButton);
}

protected void ImageButton_Click(object sender, ImageClickEventArgs e)
{
do something..;
}

within your custom control. You only want to bubble events when you want to
expose your event in the containing page.

"Teemu Keiski" wrote:

> Hi,
>
> you could access the child control in button's click event? Or if it's
> something internal in the child control, it should be informed somehow that
> the Click occurred, maybe it could wire up to an event of the parent control
> which the parent exposes publicly?
>
> --
> Teemu Keiski
> AspInsider, ASP.NET MVP
> http://blogs.aspadvice....
> http://teemu...
>
> "I am Sam" <IamSam@discussions.microsoft.com> wrote in message
> news:17145147-092D-46A8-B88D-84344234251F@microsoft.com...
> >I need to write a composite control where a click event in the
> > parent(container) class fires an event in a child control. How is this
> > possible? ie clicking a button in the parent control performs an action
> > on a
> > child control.
>
>
>