Composite custom controls events

A

apple

sorry, I send copy to webcontrols, and then I find a more relevant group,
please help me

I create a simple custom tabular control, and try for place set of controls
inside its tab tags.
<helix:tabcontrol id="Tab1" runat="server" width="100%">
<helix:tab header="Users">other controls</helix:tab>
<helix:tab header="Roles">other controls</helix:tab>
<helix:tab header="Resources">other controls</helix:tab>
</helix:tabcontrol>
Control tree with all nested controls will be created fine, but postback
events don't firing if I place other controls inside helix:tab tags, for
example the datagrid paging don't work. And databinding work correct. Why?
How I can process the postback from nested controls.

thank
 
A

Alessandro Zifiglio

you must override the onbubbleEvent method in your helixtab template and
send it up to the container.

Event bubbling is what you want. Look in the docs for more. This is an old
post where a bit was discussed. Also do not forget to implement
INamingContainer in helixTab.

Follow up on this post :

http://groups.google.com/groups?hl=...ed&ie=UTF-8&oe=UTF-8&hl=en&btnG=Google+Search

Message 13 onwards we got into event bubbling. Let me know if your stuck.
 
A

apple

Thank Alessandro for your reply, I think already about bubbling, and I have
a lot of "theoretical" questions for you or somebody else.
If I understand correctly, in my controls hierarchy all controls inside
separate tabs fire events, these events yet not propagate up through the
control hierarchy and the page that finally holds my tab control don't know
about these internal events. So if I place nested datagrid handler's inside
page class, any level of nested control hierarchy may probably block event
bubbling, because by default, an event that initiates bubbling is
automatically bubbled up through the control hierarchy, as "we can see from
the definition of the RaiseBubbleEvent method and the default implementation
of OnBubbleEvent" in Control class. I read this in a book Developing
Microsoft ASP.NET Server Controls and Components. Very likely this
"blocking" level is a collection of tabs which inherits CollectionBase an
don't have default bubbling features. Can you comment these thoughts?
 
A

Alessandro Zifiglio

Apple, actually the events fire in your Template helixTab, however the idea
is to trap this event and send it up. I Understand your concern about the
dataGrid control, which is a Templated Control in itself, but you could
actually trap these events and send them up, even if in my personal opinion
I find this not to be very smart. Reason being that you could have any
controls in your template not just a datagrid and it makes it very hard to
keep trapping and exposing these events in your container, and in the end
you will end up with a cluttered control that exposes events of controls
that are not directly part of the control but are nested controls. This is
ok for normal click events etc but for controls like the the datagrid you
got --onitemcreated --onitemdatabound and many others, for whom you would
have to trap the event individually and then expose it to the consumers of
your custom control. For templated controls the idea is to provide one
handler for specific events, and because most controls have a click event, i
think you should bubble this up and expose one handler for all click events
and then let the end user distinguish every click by checking the
ArgumentName attribute for the buttons they defined etc.

As for controls like the dataGrid an easier way to workaround would be to
add your datagrid to a UserControl and then add the UserControl as a
childControl in your Template. This is because a usercontrol has its own
code-behind class where you can code, and use your dataGrids event handlers
like you would on any page. If you went this route then you wont need to
bother with the hassles of bubbling events for Templated Controls like the
DataGrid --DataList --Repeater etc which in turn bubble events for their
ChildControls :)
 
A

Alessandro Zifiglio

Apple, in my last post i said that you could bubble up the events for the
datagrid control but now that I think of it, bubbling up the dataGrid
controls events is not the real problem but trying to distinguish which
dataGrid control fired the event as there is no way you can pass an
identifier like we could have done through the CommandArgument or
CommandName properties exposed by contros that postback like the button
Control etc.

So what you need to do is have the consumers of your custom control wrap
their datagrid control and the like within a usercontrol and add the
usercontrol and not the dataGrid directly, like I had mentioned in my
previous post.
 
A

apple

Alessandro, thanks
only one way we have as a result for my simple tab control - bubbling?
it is of course not convenient, because I don't know what controls may
contain tab container...
:(
 
A

Alessandro Zifiglio

Bubbling is great and you dont need to know what control is contained ahead
of time, but what events you want to trap and bubble up. Once bubbled, you
want to expose a handler for that specific event. What you dont know is
which control fired the event, because you can have 10 buttons in your
template and every one of them can fire a click event. Question : So, how do
we know who fired this event if we have one generic click event handler
exposed by our control ?
Answer : For every button we use the CommandName property and set an
identifier here : like button1.CommandName = "Button1"

Now in the click event handler we expose to end users of our control, or
even in the container of our template, which will fire everytime a click
event occurs in our template, is to check in this manner :

Sub MyCustomControl_Click(sender As Object, e As MyControl.CommandEventArgs)
if e.CommandName = "Button1" then
'Take action because button1 was clicked.
End sub
End Sub 'MyCustomControl_Click


This is possible because the CommandEventArgs object contains data about the
Command event that can be accessed in the event handler. The dataGrid
control does not expose the CommandEventArgs object making it impossible to
pass any data and hence we got no identifier, when for example, an
onItemDataBound event is fired. If you had one dataGrid control no problem.
If you had multiple datagrids in your template then you wont know how to
differentiate btw dataGrids. Also note that this is only my own personal
reasoning and I am speaking theorically.

It makes sense to me to tell consumers of your control that if they wanted
to nest datagrids, to do this wrapping them within usercontrols whereas to
nesting the grid directly and not try and bubble up events for templated
controls like the dataGrid. This will also give them greater control on what
is going on without limiting them.
 
A

Alessandro Zifiglio

oops, typo error : its "End If" and not "End sub" ;P

Sub MyCustomControl_Click(sender As Object, e As MyControl.CommandEventArgs)
if e.CommandName = "Button1" then
'Take action because button1 was clicked.
End If
End Sub 'MyCustomControl_Click
 
A

apple

Alessandro, thanks for your considerations
I don't fully grasped everything you write in all your replies. I need more
time to think it over and just to do more homework. I'm not ready at present
for a subsequent talk.
Here is the hyperlink to the similar tab control
http://www.devasp.net/net/Net/search/res/r11927.html
My variant also have logic like this (with collection), the difference in
rendering only. I save all your comprehensive post's for further
experimental investigation :)) . I will not take up any more of your time,
thank you muchly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top