.nettabcontrolascxcalendar-control

Calendar control on tabbed ascx page


I have an ASPX page which has 2 tabs.

Each tabs code registered as ASCX. I have individual custom Calendar controls at both pages. Now my calendar control doesn't work on the combined page but works if the pages are rendered individually.

Code in main ASPX page

<%@ Page Language="VB" %>
<%@ Register Src="~/Content/Page1.ascx" TagPrefix="Content" TagName="Page1" %>
<%@ Register Src="~/Content/Page2.ascx" TagPrefix="Content" TagName="Page2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="PageBody" Runat="Server">
    <asp:ScriptManager ID="Main" runat="server" />
    <ajaxToolkit:TabContainer ID="tcRecords" ActiveTabIndex="0" runat="server">
        <ajaxToolkit:TabPanel ID="tpSuccess" HeaderText="Success Records" runat="server">
            <ContentTemplate>
                <Content:Page1 ID="P1" runat="server" />
            </ContentTemplate>
        </ajaxToolkit:TabPanel>
        <ajaxToolkit:TabPanel ID="tpFailed" HeaderText="Failed Records" runat="server">
            <ContentTemplate>
                <Content:Page2 ID = "P2" runat="server" />
            </ContentTemplate>
        </ajaxToolkit:TabPanel>
    </ajaxToolkit:TabContainer>
</asp:Content>

Code in both ASCX pages

<%@ Register Src="~/UIControls/Calendar.ascx" TagPrefix="UICtrl" TagName="Calendar" %>
<UICtrl:Calendar ID="Cal1" runat="server" />

Solution

  • I have seen behavior like this before when using multiple instances of the same user control in one aspx page. Are you using any Session variables or view states? You need to make sure you are assigning these things with unique ID's otherwise, you will mix them up between controls. You can rename them like this:

    ViewState(Me.UniqueID & "_SomeValue")
    

    or

    Session(Me.UniqueID & "_someOtherValue")
    

    This creates a view state and session variable with unique ID's