Question

I'm having some trouble getting a command link in a gridview to maintain it's ability to change tabs after the initial postback. So below you will see the structure of my content (heavily simplified):

  <ajaxToolkit:TabContainer runat="server" ID="tabBody">     
    <ajaxToolkit:TabPanel runat="server" ID="tabPanel1">
      <ContentTemplate>
        <asp:UpdatePanel runat="server" ID="updPanel1">
          <ContentTemplate>
            <asp:Gridview runat="server" ID="grd1" OnRowCommand="grd1_RowCommand" OnRowDataBound="grd1_RowDataBound">
                <asp:TemplateField>
                  <ItemTemplate>
                     <asp:LinkButton ID="lnkChangePanels" runat="server" CommandArgument='<%#Eval("id") %>' CommandName="gotopanel2" Text='<%#Eval("FirstName") & " " & Eval("LastName")%>' /> 
                  </ItemTemplate>
               </asp:TemplateField>
            </asp:Gridview>
          </ContentTemplate>
        </asp:UpdatePanel>
      </ContentTemplate>
    </ajaxToolkit:TabPanel>
    <ajaxToolkit:TabPanel runat="server" ID="tabPanel2">
      <ContentTemplate>
        <asp:UpdatePanel runat="server" ID="updPanel2">
          <ContentTemplate>
            <asp:Gridview runat="server" ID="grd2">

            </asp:Gridview>
          </ContentTemplate>
        </asp:UpdatePanel>
      </ContentTemplate>
    </ajaxToolkit:TabPanel>
 </ajaxToolkit:TabContainer>

In order to fill the gridview on panel 1, there is a search box which the user types into and I call a function to bind a linq query to it.

Now I add the rowcommand as a postback trigger on rowdatabound:

Protected Sub grd1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim lb As LinkButton = CType(e.Row.FindControl("lnkChangePanels"), LinkButton)
            If Not lb Is Nothing Then
                ToolkitScriptManager1.RegisterPostBackControl(lb)
            End If
        End If
    End Sub

Then here is the code I have to trigger the tab panel to change (and do some other stuff):

Protected Sub grd1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grd1.RowCommand
    Dim id = e.CommandArgument.ToString()
    Select Case e.CommandName
       Case "gotopanel2"
            eventDetails(id, "C")
            tabBody.ActiveTab = tabPanel2
    End Select
End Sub

This causes a proper postback and changes the tab, everything works as intended. But if I go back to the first tab and try clicking another row in gridview 1, nothing happens.

Is there a way to structure this so the that either the tab can change without losing the postback trigger or am I going about this all wrong?

Thanks.

Was it helpful?

Solution

Postback trigger is not lost. Problem is caused by individual UpdatePanels in each tab.

Put entire TabContainer within UpdatePanel and you can remove UpdatePanels from tabs (but you don't have to). Make sure that UpdateMode of that new panel is set to "Always".

I think the reason why it does not change in your example is that UpdatePanel only refreshes it's own content and attribute that decides if tab is visible or not is set for div (tabPanel) outside that UpdatePanel. When you go back to tab with grid you do it client-side by clicking on it and that's when it goes wrong.

To get to the bottom of the problem and figure out why it does work during the first postback you would probably have to debug ajax toolkit javascript for TabContainer control.

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