当我点击使用li
和runat=server
创建的不同标签时,我有以下代码来加载控件。
但我的问题是我需要根据哪个li
标签处于活动状态来加载控件。如何区分从后面的代码中单击哪个选项卡(li
)?
这是我的HTML代码:
<ul class="tabcontrols l_tinynav1">
<li class="current" id="li_ActivationBySOID" runat="server">
<a id="a1" onserverclick="lnk_ActSOID_Click" runat="server" title="Capacity and Flex :Order Number based">Order Number</a>
</li>
<li class="" id="li_Activation" runat="server"><a id="AnchorButton" onserverclick="lnk_Act_Click" runat="server" title="Capacity and Flex:Certificated Id based">Full Redemption</a>
</li>
<li class="" id="li_BActivation" runat="server">
<a id="a_BACt" onserverclick="lnk_BA_Click" runat="server" title="Flex: Certificate Id based">Partial Redemption</a>
</li>
</ul>
这是我背后的代码:
loadcontrols(ddlPType.SelectedIndex); // I need to load if li_Activation is active
if (Request.QueryString["PType"] != null)
{
int ptype = -1;
if (Int32.TryParse(Request.QueryString["PType"].ToString(), out ptype))
{
loadcontrols(ptype);
ddlPType.SelectedIndex = ptype;
}
}
loadOrderNumberControls(ddlPType.SelectedIndex); // I need to load if li_ActivationBySOID is active
if (Request.QueryString["PType"] != null)
{
int ptype = -1;
if (Int32.TryParse(Request.QueryString["PType"].ToString(), out ptype))
{
loadOrderNumberControls(ptype);
ddlPType.SelectedIndex = ptype;
}
}
有人可以就此提出任何建议吗?
更新
我尝试使用HiddenField
这样但我在后面的代码中变为空string
:
<script>
$(document).ready(function () {
$("#myList li").click(function () {
$("#hdnTabField").val($(this).attr('id'));
});
})
</script>
<ul class="tabcontrols l_tinynav1" id="myList">
<asp:HiddenField ID="hdnTabField" runat="server" />
<li class="current" id="li_ActivationBySOID" runat="server">
<a id="a1"
onserverclick="lnk_ActSOID_Click"
runat="server"
title="Capacity and Flex :Order Number based">Order Number
</a>
</li>
<li class="" id="li_Activation" runat="server">
<a id="AnchorButton"
onserverclick="lnk_Act_Click"
runat="server"
title="Capacity and Flex:Certificated Id based">Full Redemption
</a>
</li>
<li class="" id="li_BActivation" runat="server">
<a id="a_BACt"
onserverclick="lnk_BA_Click"
runat="server"
title="Flex: Certificate Id based">Partial Redemption
</a>
</li>
</ul>
在代码背后:
var selectedTab = hdnTabField.Value;
选定的标签获取空值。
答案 0 :(得分:0)
尝试为name
元素使用id
属性而不是li
属性。使用id
属性,您的控件将具有id
之类:
ContentPlaceHolderName_liNameId
使用name
属性
<li class="" name="li_Activation" runat="server">[...]</li>
然后像这样更改你的JavaScript:
$("#myList li").click(function () {
$('input[id$=hdnTabField]').val($(this).attr('name'));
});
然后,您应该为隐藏字段获取正确的值。