我试图创建一个Ajax工具包TabContainer,在每个选项卡上具有“上一个”和“下一个”链接。我已将更新面板添加到每个选项卡容器中,以尝试从一个选项卡进入下一个选项卡而无需回发。使用下面显示的代码,单击标签页眉(GOOD)时不会触发页面重新加载,但是单击上一个和下一个(BAD)的图像按钮时会触发页面重新加载。 (请参阅pageLoad函数)。
请注意,每个图像按钮都有一个ID,UpdateMode是有条件的,而ChildrenAsTrigers是false。我的site.master有一个ajaxscriptmanager。
是否有任何直接的方式通过图像按钮在选项卡中进行分页而不每次都回发?谢谢。
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script type="text/javascript">
function MoveTab(num) {
var container = $find('<%=TabContainer1.ClientID %>');
container.set_activeTabIndex(num);
}
function pageLoad(sender, args) {
alert("pageload fired");
}
</script>
<ajaxToolkit:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0" Width="940">
<ajaxToolkit:TabPanel ID="TabPanelIntro" runat="server" HeaderText="Introduction">
<ContentTemplate>
<asp:UpdatePanel ID="UpdatePanel0" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false" >
<ContentTemplate>
<asp:Label id="Label1" runat="server" Text="Tab 0"/>
<asp:ImageButton ID="Next0" runat="server" ImageUrl="~/_img/next.png" ToolTip="Next" OnClientClick="MoveTab(1);" />
<br />
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanel ID="TabPanelProgram" runat="server" HeaderText="Program">
<ContentTemplate>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false" >
<ContentTemplate>
<asp:Label id="Label2" runat="server" Text="Tab 1" />
<asp:ImageButton ID="Next1" runat="server" ImageUrl="~/_img/next.png" ToolTip="Next" OnClientClick="MoveTab(2);" />
<asp:ImageButton ID="Prev1" runat="server" ImageUrl="~/_img/prev.png" ToolTip="Previous" OnClientClick="MoveTab(0);" CssClass="formpager" />
<br />
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanel ID="TabPanelSubmit" runat="server" HeaderText="Final">
<ContentTemplate>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<asp:Label id="Label13" runat="server" Text="Tab 2" CssClass="allcaps" />
<asp:ImageButton ID="Prev2" runat="server" ImageUrl="~/_img/prev.png" ToolTip="Previous" OnClientClick="MoveTab(1);" CssClass="formpager" />
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</ajaxToolkit:TabPanel>
</ajaxToolkit:TabContainer>
</asp:Content>
最佳答案
只需在调用客户端函数后添加return false即可避免回发。我只是尝试它而工作
<act:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0" Width="940">
<act:TabPanel ID="TabPanelIntro" runat="server" HeaderText="Introduction">
<ContentTemplate>
<asp:UpdatePanel ID="UpdatePanel0" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<asp:Label ID="Label3" runat="server" Text="Tab 0" />
<asp:ImageButton ID="Next0" runat="server" ImageUrl="~/_img/next.png" ToolTip="Next"
OnClientClick="MoveTab(1);return false;" />
<br />
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</act:TabPanel>
<act:TabPanel ID="TabPanelProgram" runat="server" HeaderText="Program">
<ContentTemplate>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<asp:Label ID="Label4" runat="server" Text="Tab 1" />
<asp:ImageButton ID="Next1" runat="server" ImageUrl="~/_img/next.png" ToolTip="Next"
OnClientClick="MoveTab(2); return false;" />
<asp:ImageButton ID="Prev1" runat="server" ImageUrl="~/_img/prev.png" ToolTip="Previous"
OnClientClick="MoveTab(0);return false;" CssClass="formpager" />
<br />
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</act:TabPanel>
<act:TabPanel ID="TabPanelSubmit" runat="server" HeaderText="Final">
<ContentTemplate>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<asp:Label ID="Label13" runat="server" Text="Tab 2" CssClass="allcaps" />
<asp:ImageButton ID="Prev2" runat="server" ImageUrl="~/_img/prev.png" ToolTip="Previous"
OnClientClick="MoveTab(1);return false;" CssClass="formpager" />
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</act:TabPanel>
关于asp.net - 使用javascript和更新面板的TabContainer分页,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2867800/