思路:母版頁隱藏控件 從內容頁接收值 JS根據接受的值控制菜單項的現實
母版頁:
隱藏控件:
復制代碼 代碼如下:
<asp:Label ID="Lbl_X" runat="server" Text="text" style="display:none"></asp:Label>
<asp:Label ID="Lbl_Xn" runat="server" Text="text" style="display:none"></asp:Label>
JS:
<%-- 設置選中--%>
<script type="text/javascript">
var X = document.getElementById('<%=this.Lbl_X.ClientID %>').innerText;
var Xn = document.getElementById('<%=this.Lbl_Xn.ClientID %>').innerText;
var div = document.getElementById(X);
if (div != null) {
div.setAttribute("class", 'nav-top-item current');
}
var div2 = document.getElementById(Xn);
if (div != null) {
div2.setAttribute("class", 'current');
}
</script>
內容頁給母版頁隱藏空間賦值:
//設置母版頁Lable的值,以控制菜單項CSS
復制代碼 代碼如下:
Label X = (Label)this.Master.FindControl("Lbl_X");
X.Text = "A";
Label Xn = (Label)this.Master.FindControl("Lbl_Xn");
Xn.Text = "A1";