使用“TabContainer”和“TabPanel” Ajax 工具包
我在一个页面上有几个选项卡,它总是默认为第一个选项卡,但是当单击链接时,我希望它使用 javascript 选择不同的选项卡。如何使用 Javascript 选择选项卡?
现在,因为默认选择第一个选项卡,所以 JavaScript 会抛出错误,指出 pnlTab2 不可见或不存在。但是,如果我手动单击该选项卡,然后单击链接,它会正确地聚焦在该选项卡上吗?
我是 C# 和 Javascript 新手,有人可以帮助我吗?我如何使用 javascript 选择第二个选项卡,然后聚焦,这样它就不会给我错误?
谢谢
function DoFocus() {
var pnlTab1 = document.getElementById('<%=pnlTab1.ClientID%>');
var pnlTab2 = document.getElementById('<%=pnlTab2.ClientID%>');
if (pnlTab2 != null ) {
//I WANT TO SELECT THE TAB HERE
document.getElementById('<%=pnlCustomerReviews.ClientID%>').focus();
}
else {
//OR SELECT THIS ONE
document.getElementById('<%=pnlTab2.ClientID%>').focus();
}
return false;
}
<asp:UpdatePanel ID="UpdatePnl" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<ajaxToolKit:TabContainer runat="server" id="myTabs" CssClass="CustomTabStyle">
<ajaxToolKit:TabPanel ID="pnlTab1" runat="server" HeaderText="Tab 1">
<ContentTemplate>
<table>
<tr>
<td>
<div class="Tab1">
<asp:Label ID="lblPnl1" runat="server"></asp:Label>
</div>
</td>
</tr>
</table>
</ContentTemplate>
</ajaxToolKit:TabPanel>
<ajaxToolKit:TabPanel ID="pnlTab2" runat="server" HeaderText="Tab2">
<ContentTemplate>
<table>
<tr>
<td>
<div class="Tab2">
<asp:Label ID="lblPnl2" runat="server"></asp:Label>
</div>
</td>
</tr>
</table>
</ContentTemplate>
</ajaxToolKit:TabPanel>
</ajaxToolKit:TabContainer>
</ContentTemplate>
</asp:UpdatePanel>
I have a few tabs on a page and it always defaults to the first tab , but when a link is clicked i want it to select a diferent tab using javascript. How can I select the tab with Javascript?
Right now, because the default is selecting the first tab, javascript throws an error that either pnlTab2 is not visible or does not exist. But if I manually click on the tab and then on the link it focuses on that tab correctly?
I am new in C# and Javascript, can anyone please help me?, how can I select the second tab using javascript and then focus so that it does not give me error?
Thank you
function DoFocus() {
var pnlTab1 = document.getElementById('<%=pnlTab1.ClientID%>');
var pnlTab2 = document.getElementById('<%=pnlTab2.ClientID%>');
if (pnlTab2 != null ) {
//I WANT TO SELECT THE TAB HERE
document.getElementById('<%=pnlCustomerReviews.ClientID%>').focus();
}
else {
//OR SELECT THIS ONE
document.getElementById('<%=pnlTab2.ClientID%>').focus();
}
return false;
}
<asp:UpdatePanel ID="UpdatePnl" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<ajaxToolKit:TabContainer runat="server" id="myTabs" CssClass="CustomTabStyle">
<ajaxToolKit:TabPanel ID="pnlTab1" runat="server" HeaderText="Tab 1">
<ContentTemplate>
<table>
<tr>
<td>
<div class="Tab1">
<asp:Label ID="lblPnl1" runat="server"></asp:Label>
</div>
</td>
</tr>
</table>
</ContentTemplate>
</ajaxToolKit:TabPanel>
<ajaxToolKit:TabPanel ID="pnlTab2" runat="server" HeaderText="Tab2">
<ContentTemplate>
<table>
<tr>
<td>
<div class="Tab2">
<asp:Label ID="lblPnl2" runat="server"></asp:Label>
</div>
</td>
</tr>
</table>
</ContentTemplate>
</ajaxToolKit:TabPanel>
</ajaxToolKit:TabContainer>
</ContentTemplate>
</asp:UpdatePanel>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:http://forums.asp.net/t/1127834.aspx
Try this: http://forums.asp.net/t/1127834.aspx