Я хочу показать код, который будет идти в методе Page_Load из Products.aspx, который использует общественную собственность и добавляет необходимый CSS класс гиперссылкеДобавьте необходимый CSS класс гиперссылке в PageLoad
MasterPage код :
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MyMaster.master.cs" Inherits="MyMaster.MyMaster" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server">
<title></title>
<style>
ul {
float: left; width: 100%; padding: 0; margin: 0;
list-style-type: none;
}
a {
float: left; width: 6em;
text-decoration: none; color: white; background-color: purple; padding: 0.2em 0.6em;
border-right: 1px solid white;
}
a.selected {
background-color: fuchsia;
}
li {
display: inline;
}
</style> </head> <body>
<form id="form1" runat="server"> <div>
<!--CSS-driven menu --> <ul id="ae" class="selected">
<li><a href="Home.aspx" >Home</a></li>
<li id="Product"><a href="Products.aspx" >Products</a></li>
<li><a href="AboutUs.aspx" >About Us</a></li>
<li><a href="ContactUs.aspx" >Contact Us</a></li>
</ul>
<asp:ContentPlaceHolder id="MainContent" runat="server">
</asp:ContentPlaceHolder>
<asp:ContentPlaceHolder id="FeaturedContent" runat="server">
</asp:ContentPlaceHolder>
</div>
</form> </body> </html>
<script type='text/javascript'>
function mouseUp(element) { element.style.background = 'red'; }
function mouseDown(element) { element.style.background = 'blue'; }
</script>
MyMaster.Master.cs:
namespace MyMaster
{
public partial class MyMaster : System.Web.UI.MasterPage
{
public String anc
{
get { return anc; }
set { anc = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
Product.aspx.cs
namespace MyMaster
{
public partial class Products : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//MyMaster m = new MyMaster();
//Master.MasterHyperlink.
// Master.MasterHyperlink.Navigateurl = "Products.aspx";
Control cntb;
cntb = this.FindControl("ae");
cntb.CssClass = "Selected";
}
}
}
}