locked
Dynamically Load UserControl on Tab Click RRS feed

  • Question

  • User-725520357 posted

    Hi,

      i want to  Load UserControl Dynamically when Ajax Tab is Clicked...

     i have code for that...it is working fine when tab is clicked once...if i click the same tab again datas disappears...

      Please help me with this...

    my code is:

     

    Default
    ------------------
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="Menu.ascx.cs" Inherits="UserControl_Menu" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
    
     
     <%@ Reference Control="~/UserControl/Emp1.ascx"  %>
       <%@ Reference Control="~/UserControl/Emp2.ascx" %>
      <%@ Reference Control="~/UserControl/Emp3.ascx" %>
    
             <script language="javascript" type="text/javascript">
                 function ActiveTabChanged(sender, e) {
                     // use the client side active tab changed       
                     // event to trigger a callback thereby
                     // triggering the server side event.
                    
                __doPostBack('<%= Tab1.ClientID %>',
          sender.get_activeTab().get_headerText());
                  
                    
                     
                 }
          </script>  
     
     
     
     <asp:ScriptManager   
                ID="ScriptManager1"  
                runat="server"  
               EnablePartialRendering="True">  
            </asp:ScriptManager> 
            
           
            
          <asp:UpdatePanel ID="UpdatePanelmain" runat="server">
          
            <ContentTemplate>
                <cc1:TabContainer ID="Tab1" runat="server" OnClientActiveTabChanged="ActiveTabChanged" OnActiveTabChanged="AddUserContol">
                        <cc1:TabPanel ID="TabPanel1" runat="server" HeaderText="TabPanel1">
                             <ContentTemplate>
                      <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                     <ContentTemplate>
                     
                     </ContentTemplate>
                       </asp:UpdatePanel>
                            </ContentTemplate>
                        </cc1:TabPanel>
                        
                        <cc1:TabPanel runat="server" ID="TabPanel2" HeaderText="TabPanel2">
                        <ContentTemplate>
                            <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                                <ContentTemplate>
    
                                </ContentTemplate>
                            </asp:UpdatePanel>
                        </ContentTemplate>
                        </cc1:TabPanel>
                        
                        
                        <cc1:TabPanel runat="server" ID="TabPanel3" HeaderText="TabPanel3">
                        <ContentTemplate>
                            <asp:UpdatePanel ID="UpdatePanel3" runat="server">
                                <ContentTemplate>
    
                                </ContentTemplate>
                            </asp:UpdatePanel>
                        </ContentTemplate>
                        </cc1:TabPanel>
                        
                </cc1:TabContainer>
            </ContentTemplate>
            <Triggers>      
                <asp:AsyncPostBackTrigger ControlID="Tab1" EventName="ActiveTabChanged" />    
            </Triggers>
            </asp:UpdatePanel> 
            
            
    <asp:PlaceHolder ID="phModule" runat="server"></asp:PlaceHolder>
    
    
    ----------------------------
    Default.ascx.cs
    -----------------------------
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using AjaxControlToolkit;
    
    public partial class UserControl_Menu : System.Web.UI.UserControl
    {
        protected ASP.usercontrol_emp1_ascx control1;
        protected ASP.usercontrol_emp2_ascx control2;
        protected ASP.usercontrol_emp3_ascx control3;
    
        protected void Page_Load(object sender, EventArgs e)
        {
           // ScriptManager1.RegisterAsyncPostBackControl(Tab1);
         
            if (!IsPostBack)
            {
                control1 = (ASP.usercontrol_emp1_ascx)LoadControl("~/UserControl/Emp1.ascx");
    
              UpdatePanel1.ContentTemplateContainer.Controls.Add(control1);
    
              
            }
        }
    
        protected void AddUserContol(object sender, EventArgs e)
        {
            if (Tab1.ActiveTab.ID == "TabPanel1")
            {
               control1 = (ASP.usercontrol_emp1_ascx)LoadControl("~/UserControl/Emp1.ascx");
               
                       UpdatePanel1.ContentTemplateContainer.Controls.Add(control1);
              
            }
    
            if (Tab1.ActiveTab.ID == "TabPanel2")
            {
               control2 = (ASP.usercontrol_emp2_ascx)LoadControl("~/UserControl/Emp2.ascx");
               
                       UpdatePanel2.ContentTemplateContainer.Controls.Add(control2);
                
            }
    
            if (Tab1.ActiveTab.ID == "TabPanel3")
            {
                control3 = (ASP.usercontrol_emp3_ascx)LoadControl("~/UserControl/Emp3.ascx");
                
                        UpdatePanel3.ContentTemplateContainer.Controls.Add(control3);
               
            }
        }
    
    }
    
    
    Sunday, July 3, 2011 1:55 AM

Answers

All replies