OK, I tried that but it wasn't successful as I'm getting an error now. This is what I have done. In the Site.master.aspx.cs I have this code:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.IO;
public partial class Site : System.Web.UI.MasterPage
{
public void ActiveClass(string whatPage) {
string PageName = whatPage;
switch (PageName) {
case "HomeLink":
HomeLink.CssClass = "active";
break;
case "AboutLink":
AboutLink.CssClass = "active";
break;
case "OPLink":
OPLink.CssClass = "active";
break;
}
}
}
In my content pages I call the function in this fashion:
Home.aspx.cs:
public partial class Home : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Site master = new Site();
master.ActiveClass("HomeLink");
}
}
About.aspx.cs
...
public partial class About : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Site master = new Site();
master.ActiveClass("AboutLink");
}
}
Other_projects.aspx.cs
...
public partial class Other_projects : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Site master = new Site();
master.ActiveClass("OPLink");
}
}
When I run the application, I don't get any error in the compiler but the webpage returns one of those Server error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set …