I am using Ajax tab control, which includes grids in each tab. The grid have drop down list and button and I want to fire gridview's RowCommand event on button click of gridview Row. But the problem is whenever I click on the button, Tabcontainet_ActiveTabChanged event is fired and grid view is bind again before it fire the RowCommand event.
I can not understand why this event is fired automatically even though I am not firing it intentionally. How can I fire RowCommand event in such cases?? I tried both with update panel and without update panel.
That's very strange but TabContainer fires ActiveTabChanged event on each postback if active tab changed or if actual ActiveTabIndex property value equals to 0. I can't find out any reason for such behavior so use solution below on on your own risk. Actually there are two solutions available: the first one is to download AjaxControlToolkit sources, change TabContainer control LoadPostData method and use custom dll :
Actual method:
protected override bool LoadPostData(string postDataKey, NameValueCollection postCollection)
{
int tabIndex = ActiveTabIndex;
bool result = base.LoadPostData(postDataKey, postCollection);
if (ActiveTabIndex == 0 || tabIndex != ActiveTabIndex)
{
return true;
}
return result;
}
Just remove ActiveTabIndex == 0
condition from the code above.
Or you can create your own class inherited from the TabContainer, override that method and use this class instead of the default:
namespace AjaxControlToolkit
{
/// <summary>
/// Summary description for MyTabContainer
/// </summary>
public class MyTabContainer : TabContainer
{
protected override bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
{
int tabIndex = ActiveTabIndex;
if (SupportsClientState)
{
string clientState = postCollection[ClientStateFieldID];
if (!string.IsNullOrEmpty(clientState))
{
LoadClientState(clientState);
}
}
if (tabIndex != ActiveTabIndex)
{
return true;
}
return false;
}
}
}