weeb
Explore posts from servers❔ Element's class in Master not changing
Hi, i have the following code in
I'm trying to add active class to li when their respective button is clicked,
Here's my code in
template.Master
<li id="list_home" runat="server" class="active">
<asp:Button ID="home_button" runat="server" Text="Home" OnClick="home_button_Click"/>
</li>
<li id="list_catalog" runat="server">
<asp:Button ID="catalog_button" runat="server" Text="Catalog" OnClick="catalog_button_Click" />
</li>
<li id="list_purchase" runat="server">
<asp:Button ID="purchase" runat="server" Text="Purchase" OnClick="purchase_Click" />
</li>
<li id="list_profile" style="float:right"><a id="profile">Profile</a></li>
<li id="list_home" runat="server" class="active">
<asp:Button ID="home_button" runat="server" Text="Home" OnClick="home_button_Click"/>
</li>
<li id="list_catalog" runat="server">
<asp:Button ID="catalog_button" runat="server" Text="Catalog" OnClick="catalog_button_Click" />
</li>
<li id="list_purchase" runat="server">
<asp:Button ID="purchase" runat="server" Text="Purchase" OnClick="purchase_Click" />
</li>
<li id="list_profile" style="float:right"><a id="profile">Profile</a></li>
template.Master.cs
private HtmlGenericControl prev = null;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void home_button_Click(object sender, EventArgs e)
{
list_home.Attributes["class"] = "active";
if(this.prev != null)
{
prev.Attributes["class"] = "";
}
prev = list_home;
Response.Redirect("home.aspx");
}
protected void catalog_button_Click(object sender, EventArgs e)
{
list_catalog.Attributes["class"] = "active";
if (this.prev != null)
{
prev.Attributes["class"] = "";
}
prev = list_catalog;
Response.Redirect("catalog.aspx");
}
protected void purchase_Click(object sender, EventArgs e)
{
list_purchase.Attributes["class"] = "active";
if (this.prev != null)
{
prev.Attributes["class"] = "";
}
prev = list_purchase;
Response.Redirect("purchase.aspx");
}
}
private HtmlGenericControl prev = null;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void home_button_Click(object sender, EventArgs e)
{
list_home.Attributes["class"] = "active";
if(this.prev != null)
{
prev.Attributes["class"] = "";
}
prev = list_home;
Response.Redirect("home.aspx");
}
protected void catalog_button_Click(object sender, EventArgs e)
{
list_catalog.Attributes["class"] = "active";
if (this.prev != null)
{
prev.Attributes["class"] = "";
}
prev = list_catalog;
Response.Redirect("catalog.aspx");
}
protected void purchase_Click(object sender, EventArgs e)
{
list_purchase.Attributes["class"] = "active";
if (this.prev != null)
{
prev.Attributes["class"] = "";
}
prev = list_purchase;
Response.Redirect("purchase.aspx");
}
}
2 replies