Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a Scenario in which i have used ajax:TabContainer to load grid view inside User Control, on click of each tab a user control is loaded, Whats going wrong is on click of each Tab in ajax:TabContainer javascript is called as Many times as the tab is clicked.

eg: if i click tab1 the js loads 1's and if i click tab3 the js loads twice, and if i click tab1 again the js loads thrice and so on.

I found this when i had placed an alert message in js file.

Here is my code

ASP.NET
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btnSearch" />
                <asp:AsyncPostBackTrigger ControlID="MainTab" />
            </Triggers>
            <ContentTemplate>
                <div>
                    <asp:HiddenField ID="HiddenField1" runat="server" ClientIDMode="Static" />
                </div>
                <div id="DivGridUserControl" class="DivJLGridUserControl">
                    <ajax:TabContainer ID="MainTab"  runat="server" AutoPostBack="true" ActiveTabIndex="0" CssClass="fancy fancy-green ajax__tab_header">
                        <ajax:TabPanel ID="TabStatus"  runat="server">
                            <headertemplate>
                            Status
                        </headertemplate>                        
                            <contenttemplate>
                            <div >
                                <uc1:JLStatus  runat="server" ID="GrvJobListStatus" />
                            </div>
                        </contenttemplate>
                        </ajax:TabPanel>
                        <ajax:TabPanel ID="TabShip"  runat="server">
                            <headertemplate>
                            Ship
                        </headertemplate>
                            <contenttemplate>
                                <uc1:JLShip  runat="server" ID="GrvJobListShip"   />
                        </contenttemplate>
                        </ajax:TabPanel>
                        <ajax:TabPanel ID="TabAcct"  runat="server">
                            <headertemplate>
                            Acct
                        </headertemplate>
                            <contenttemplate>
                                <uc1:JLAcct  runat="server" ID="GrvJobListAcct"  />
                        </contenttemplate>
                        </ajax:TabPanel>
                        <ajax:TabPanel ID="TabMschedule"  runat="server">
                            <headertemplate>
                            Mschedule
                        </headertemplate>
                            <contenttemplate>
                                <uc1:JLMschedule  runat="server" ID="GrvJobListJLMschedule"  />
                        </contenttemplate>
                        </ajax:TabPanel>
                    </ajax:TabContainer>
            </ContentTemplate>
        </asp:UpdatePanel>



Can some one tell how I can come out of this.

Thanks in advance.
Posted
Comments
Sreekanth Mothukuru 13-Sep-14 8:21am    
how you are loading js on each click? I see no js in this script !!
Yashwanth R 15-Sep-14 0:20am    
Actually I have a vertical menu which slides open on a image click and slides back on another image click. I have this menu in master page and have written sliding function masterpage.js; on expansion of vertical menu i need to resize the content page which holds the ajax:TabContainer, so I have the resize function called on same image button click of menu in content page js file.


If i place/call the resize function from master page js file itself the content js will not load multiple times.

Thanks for the reply.
Sreekanth Mothukuru 15-Sep-14 1:38am    
I think instead of calling resize js method on the image client (i.e., before loading the content page), you need to call the it after loading the content page (Tab container) using any of the following method server side.

Page.ClientScript.RegisterStartupScript
ScriptManager.RegisterStartupScript

http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerstartupscript%28v=vs.110%29.aspx
http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.registerstartupscript%28v=vs.110%29.aspx

Hope this helps!
Yashwanth R 15-Sep-14 3:10am    
Ya I'm calling after content page load itself, i have called even after all the master page gets loaded, but still getting the same problem.
Sreekanth Mothukuru 15-Sep-14 5:42am    
Not sure, if I'm following you. I suspect that on each click to load user control.. you are adding same JavaScript function to the master page. This could duplicate functionality. That could be the reason JavaScript loads multiple times. Try to attach the related JavaScript within the user control and not outside.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900