How to change master page navigation style from aspx page?
How to include site navigation in master page?
A Master page in most of the ASP.Net applications conatin common contents in the site like header,footer,left menus etc.. But some of the time we need to communicate with master page content from aspx page for changing style, displaying current user details etc.
Here we are explaining how to change navigation div style in masterpage from the aspx page as per the page visits. Here we are having navigation divs Home,AboutUS,ContatcUS etc.. All this divs are in the master page. All the div background color is white and once we visited the particular page we need to set curresponding navigation div background color to blue. The steps explaining also how to access master page control from aspx page.
Steps to change style of master page from aspx page
Step 1 : For first step creating a master page with common header contents with navigations divs. Like below mentioned image, we have created 4 divs and back ground color is gray, and active page has background color is blue. CSS for menu and active menu is also given below.
ASPX page
<div class='<%= HomeMenu %>'> <div style="margin-top: 3px;"> <a href="Home.aspx”">Home</a></div> </div> <div class='<%= ShopeMenu %>'> <div style="margin-top: 3px;"> <a href="Products.aspx">Shope</a></div> </div> <div class='<%= ContactUsMenu %>'> <div style="margin-top: 3px;"> <a href="ContactUs.aspx">Contact Us</a></div> </div> <div class='<%= AboutUsMenu %>'> <div style="margin-top: 3px;"> <a href="AboutUs.aspx">About Us</a></div> </div>
CSS Style
.menubutton
{
background-color:#f2f2f2;
}
.menubuttonselect
{
background-color:#507cd1;
}
Step2 : Creating properties for each div navigation menu for style.
private string _homeMenu = "menubutton";
public string HomeMenu
{
get { return _homeMenu; }
set { _homeMenu = value; }
}
private string _shopeMenu = "menubutton";
public string ShopeMenu
{
get { return _shopeMenu; }
set { _shopeMenu = value; }
}
private string _contactUsMenu = "menubutton";
public string ContactUsMenu
{
get { return _contactUsMenu; }
set { _contactUsMenu = value; }
}
private string _aboutUsMenu = "menubutton";
public string AboutUsMenu
{
get { return _aboutUsMenu; }
set { _aboutUsMenu = value; }
}
Step 3 :
In load event of every aspx page, we need to set active menu property of the master page as per the browsing page. Suppose when a user browses contact us page we need to set ‘ContactUsMenu’ to active class from the aspx page.
protected void Page_Load(object sender, EventArgs e)
{
Master.ContactUsMenu = "menubuttonselect";
}
Leave a Reply Cancel reply
Search other topic from here
Blog Stats
- 205,524 hits
Top Posts
- How to call serverside function from client side javascript in ASP.Net?
- How to implement BalloonPopupExtender in ASP.Net/C# OR Ballon Popup Extender Sample in ASP.Net/C#
- How to create a simple Ajax Collapsible Panel Extender in asp.net
- How to PIVOT table in SQL Server / PIVOT table example in SQL Server
- How to access URL or URL parts using javascript / Get the Website URL using JavaScript
- How to create breadcrumbs in ASP.Net/C# OR Show Navigations for each pages in ASP.Net/C# OR How to implement Sitemap in ASP.Net
- How to create thumbnail image in ASP.Net/C# OR resize the image before upload in ASP.Net/C#
- How to UNPIVOT table in SQL Server / UNPIVOT table example in SQL Server
- How to Import CSV File Into SQL Server Using Bulk Insert in SQLServer?
- Listview inside another Listview Conrol in ASP.Net,C#
- How to create a news scroller using HTML marquee.
- Nested Common Table Expression(CTE) in SQL Server 2005/2008
Recent Posts
- How to implement CAPTCHA image validation in ASP.Net/C# OR CAPTCHA image validator Sample in ASP.Net/C#
- How to implement SQL Bulk Copy in SQL Server OR Bulk insert into SQL Server using SQL BulkCopy
- How to merge two data tables in ASP.Net/C# OR Merge 2 DataTables and store in a new one in ASP.Net/C#
- How to implement Password validation in ASP.Net/C# OR Implement Password strength using Jquery in ASP.Net
- How to create breadcrumbs in ASP.Net/C# OR Show Navigations for each pages in ASP.Net/C# OR How to implement Sitemap in ASP.Net
- How to create a drag able and resizable div in ASP.Net/C# OR How to make a div Dragable and Resizable using Jquery in ASP.Net/C#
- How to implement BalloonPopupExtender in ASP.Net/C# OR Ballon Popup Extender Sample in ASP.Net/C#
- How to create always visible div using Ajax/ Always visible div in ASP.Net using Ajax
- Example for All Types of SQL JOIN (Inner Join, Cross Join, Outer Join, Self Join)
- How to Create a Data Table Dynamically with sample data and Bind to Grid/Create datatable with sample data.
- How to delete large amount of rows from table in SQL
- How to Create and use Table-Valued Parameter in C# and T-SQL/ How to pass table to stored procedures in SQL
Archives
- May 2013 (1)
- October 2012 (4)
- September 2012 (6)
- July 2012 (4)
- June 2012 (1)
- May 2012 (1)
- March 2012 (2)
- February 2012 (2)
- January 2012 (1)
- October 2011 (2)
- September 2011 (5)
- August 2011 (1)
- July 2011 (6)
- June 2011 (18)
- May 2011 (14)

Hi Tuvian,
Thanks for such a nice post above. I did understand the logic yet i was not able to get it to work. I really need your help on this.
I had 2 Questions :
1) Where do i put the Step 2 code ? Should i put it in masterpage.cs file? Do i have to put it in Page_Load function in masterpage.cs?
2) I am not able to find ContactUsMenu in Master.ContactUsMenu = “menubuttonselect”;
It is giving error.
Please help as i am quite naive with .net