Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Events in server controls

Reply
Thread Tools

Events in server controls

 
 
I am Sam
Guest
Posts: n/a
 
      02-16-2008
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.
 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      03-16-2008
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.com/joteke
http://teemukeiski.net

"I am Sam" <> wrote in message
news:17145147-092D-46A8-B88D-...
>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.



 
Reply With Quote
 
 
 
 
I am Sam
Guest
Posts: n/a
 
      03-16-2008
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.com/joteke
> http://teemukeiski.net
>
> "I am Sam" <> wrote in message
> news:17145147-092D-46A8-B88D-...
> >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.

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamically adding controls with events (but events are not firing) SevDer ASP .Net 2 11-13-2007 06:33 AM
Linking events from controls, when the controls have been created =?Utf-8?B?cml2YWxAbmV3c2dyb3Vwcy5ub3NwYW0=?= ASP .Net 3 07-16-2007 04:02 PM
runtime events that generate other controls and events newbye ASP .Net 0 07-06-2006 06:27 PM
Events Events Events Please Help Chris ASP .Net Web Controls 0 08-30-2005 08:21 PM
Child controls in Composite Controls not firing events David Boike ASP .Net Web Controls 0 08-07-2003 05:39 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57