Question

Worth the discussion

what are the pro's / Con's of firing the RowClick event from a telerik radgrid with following scenario's, they all work btw ;-)

Scenario 1:

Radgrid

OnSelectedIndexChanged="RG_SelectedIndexChanged"
ClientSettings.EnablePostBackOnRowClick="true"

Code behind

protected void RG_SelectedIndexChanged(){}

Scenario 2:

Radgrid

OnItemCommand="RG_ItemCommand"
ClientSettings.EnablePostBackOnRowClick="true"

Code Behind

Protected void RG_ItemCommand()
{
 if(e.commandname == "RowClick")
{
}
}

Scenario 3:

Radgrid

OnItemCommand="RG_ItemCommand"
ClientSettings.ClientEvents.OnRowClick="RG_RowClick"

Javascript

function RG_RowClick(sender, eventArgs) {
var index = eventArgs.get_itemIndexHierarchical();
sender.get_masterTableView().fireCommand("RowClick", index);
}

Behind

Protected void RG_ItemCommand()
{
 if(e.commandname == "RowClick")
{
}
}
Was it helpful?

Solution

Scenario 1 & 2:

All events in RadGrid fires ItemCommand first. Then bubble up that event to a specific event such as SelectedIndexChanged, InsertCommand, UpdateCommand.

Basically, if you want to do something before SelectedIndexChanged event is called, you want to perform that task in ItemCommand event.

Scenario 3:

Scenario 3 just calls the server side ItemCommand event from client side.

It is basically same as Scenario 2 unless you want to perform any client side tasks even before ItemCommand is called at server side. For example, "Are you sure you want to...?"

If you do not need client side features, just simply use Scenario 1 or 2 which is much more cleaner and more maintainable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top