Willing to admit I'm a complete .NET newbie, but I have extensive experience in classic ASP, which is making this quite tricky as the whole structure of .net is completely different.
I know I'm meant to use code behind, but for now I'm happy embedding it into the pages because:
- Each page is going to be simple, so there wont be too much mixing up
- It's probably too much of a step to do everything the 'right' way, I'd rather step up to that slowly as I get to grips with .net
So excusing my lack of code behind, on this page I am trying to get the ID returned by the querystring "mid" (Menu ID), and then display a different CSS class for the menu button we are currently on. Two menu classes, navButton and navButtonO (over).
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="admin.aspx.cs" Inherits="AlphaPack._Default"
title="Administration"
%>
<script language="C#" runat="server" >
protected int menuID;
protected void Page_Load(object sender, EventArgs e)
{
string menuIDdata = Page.Request.QueryString["mid"];
menuID = 0;
// Check the user is allowed here
if (!Roles.IsUserInRole("Admin"))
{
Response.Redirect("../default.aspx");
}
// Get the menu ID
if (int.TryParse(menuIDdata, out menuID))
{
menuID = int.Parse(menuIDdata);
}else{
menuID = 0;
}
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="mainHead" runat="server" >
<title>Administration</title>
<link rel="Stylesheet" href="../style/admin.css" />
</head>
<body>
<div class="topMenu">
<div class="navButton<%if(menuID == 0){ response.write("O") }%>">
<a href="admin.aspx" class="navLink">Admin Home</a>
</div>
<div class="navButton<%if(menuID == 1){ response.write("O") }%>">
<a href="users.aspx" class="navLink">User Manager</a>
</div>
<div class="navButton<%if(menuID == 2){ response.write("O") }%>">
<a href="products.aspx" class="navLink">Products</a>
</div>
</div>
<br /><br />
<div class="subMenu">
<a href="products.aspx" class="subLink">Products</a> <a href="productCats.aspx" class="subLink">Categories</a>
</div>
<br /><br />
Welcome to the Admin
</body>
</html>
Thanks for any help, don't pull any punches.
<%if(menuID == 2){ response.write("O") }%>to<%= menuID == 2 ? "O" : string.Empty %>