Click to See Complete Forum and Search --> : onCommand vs onClick for Buttons


nabeelisnabeel
December 29th, 2009, 05:34 AM
I am wondering why there is onCommand and onClick both events for ASP:Button controls. What special purpose do they serve.

memeloo
December 29th, 2009, 08:08 AM
have you already read the explanation on msdn? I don't think so.
OnCommand (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.oncommand.aspx)
OnClick (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.onclick.aspx)

the main difference is that
The Command event is raised through the control hierarchy in the form of the BubbleEvent.

nabeelisnabeel
December 30th, 2009, 04:01 AM
Actually I read it earlier but could not get the concept of 'BubbleEvent' clearly. Can you explain it.

memeloo
December 30th, 2009, 04:27 AM
this means that when a Button is nested for example in a DataGrid, then the DataGrid's OnBubbleEvent method is automaticaly called... and so forth

Use the OnBubbleEvent method to pass an event raised by a control within the container up the page's UI server control hierarchy.

additionally you can specify the CommandName and CommandArgument.

OnBubbleEvent (http://msdn.microsoft.com/en-us/library/system.web.ui.control.onbubbleevent.aspx)

nabeelisnabeel
December 31st, 2009, 01:41 AM
does it have any practical significance.

if we have some buttons inside a GridView and every button has some CommandArguement. how can we use them. should we implement a Command event for every button of a Command Event for GridView.

memeloo
December 31st, 2009, 02:30 AM
here's a nice explanation of event bubbling: http://www.4guysfromrolla.com/articles/051105-1.aspx

The Command event is raised when the Button control is clicked. This event is commonly used when a command name, such as Sort, is associated with the Button control. This allows you to create multiple Button controls on a Web page and programmatically determine which Button control is clicked.

it looks like the Command event is a general click-event handler for a group of buttons and the CommandName property helps to distinguish which button was cliked.

but although I understand the whole concept I don't know why would I want to bubble the command event-

nabeelisnabeel
December 31st, 2009, 05:42 AM
but although I understand the whole concept I don't know why would I want to bubble the command event-
That is exactly the same thing I am thinking about right now.