當我點擊「添加標籤」按鈕時,服務器端代碼(tabs.ActiveTabIndex+=1
)更改標籤,但標籤看起來是空的。如果我點擊來回,我可以看到用戶控件呈現。我錯過了什麼嗎?用戶控件不能在AJAX控件工具包中呈現TabContainer控件
<ajaxToolkit:TabContainer ID="TabContainer1" runat="server" Height="90%" Width="100%"
ActiveTabIndex="0" OnDemand="true" AutoPostBack="false" TabStripPlacement="Top"
CssClass="ajax__tab_xp" ScrollBars="None" UseVerticalStripPlacement="false" VerticalStripWidth="120px">
<ajaxToolkit:TabPanel ID="tab1" runat="server" HeaderText="1">
<ContentTemplate>
<uc:UCCommSubmit ID="ucCommInfo" runat="server" />
</ContentTemplate>
</ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanel ID="TabPanel1" runat="server" HeaderText="" Visible="false">
<ContentTemplate>
<uc:UCCommSubmit ID="UCCommSubmit1" runat="server" />
</ContentTemplate>
</ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanel ID="TabPanel2" runat="server" HeaderText="" Visible="false">
<ContentTemplate>
<uc:UCCommSubmit ID="UCCommSubmit2" runat="server" />
</ContentTemplate>
</ajaxToolkit:TabPanel>
</ajaxToolkit:TabContainer>
<div style="padding-right: 20px; float: right">
<asp:Button ID="btnNext" runat="server" Text="Add Tab"
onclick="btnNext_Click" />
</div>
protected void btnNext_Click(object sender, EventArgs e)
{
if (TabContainer1.Tabs.Count > TabContainer1.ActiveTabIndex + 1)
{
TabContainer1.Tabs[TabContainer1.ActiveTabIndex + 1].HeaderText = (TabContainer1.ActiveTabIndex + 1).ToString();
TabContainer1.Tabs[TabContainer1.ActiveTabIndex+1].Visible = true;
TabContainer1.ActiveTabIndex += 1;
}
}
謝謝蒂姆,非常徹底的步驟,我很感激。首先,出於某種原因,我似乎無法從前端訪問標籤,上面的JavaScript給我定義了set_activeTab函數!然後我試圖將autopostback設置爲true,這似乎解決了問題,然後我將scriptmanager更改爲toolkitscript管理器,然後我嘗試將autopostback設置爲false我得到了用戶控件來渲染就好... automagically! :) – nolimit