Masterpage and Content page
-
Hi. Regarding the relation between a Masterpage and some Content page I believe that sometimes it´s a bit difficult to decide where is the best place (Master or Content page) to put a Control. For example, I have a set of menu items (from a Menu control) that are displayed as Tabs. Suppose I have only 3 menu items that I call AAA,BBB,CCC ... when I click in AAA it should call the A.aspx page, the BBB > B.aspx and CCC > C.aspx ... The Menu control is in the masterpage named Master.master and A.aspx, B.aspx and C.aspx use this master page. I can think of 2 alternatives when building this Menu Items: 1st > I set the url attribute like AAA > url="~/A.aspx" and similar to the other menu items ... so when I click in any of these menu items I´ll be directed to the respective url or 2nd > I don´t use the url attribute and catch the OnMenuItemClick event and then create code to switch to the proper url Since I´m using Tabs, it would be nice to set the 'Active or Selected' Tab after the user clicks it. In the 2nd approach I can set the e.Item.Selected = true; but the Css used to mark the selected item will not work because after the click, the current page will be redirected to the proper page and the selected item will not be selected anymore. So I´ll have to end up creating complex code just to mark the selected item, probably in the current page (A,B or C.aspx) referencing the Menu control in the master page. I believe there is a simple approach to this situation. What is the best way to set the selected/active tab? This is not hard when using plain html pages, but this master/content page relation are a bit confusing ... I already read this interesting article: http://www.dotnetslackers.com/XML/re-27950\_Capture\_Master\_Page\_Events\_in\_Content\_Pages\_ASP\_NET\_2\_0.aspx, but I think there must have a simple approach to this situation which unfortunately I just don´t get.
-
Hi. Regarding the relation between a Masterpage and some Content page I believe that sometimes it´s a bit difficult to decide where is the best place (Master or Content page) to put a Control. For example, I have a set of menu items (from a Menu control) that are displayed as Tabs. Suppose I have only 3 menu items that I call AAA,BBB,CCC ... when I click in AAA it should call the A.aspx page, the BBB > B.aspx and CCC > C.aspx ... The Menu control is in the masterpage named Master.master and A.aspx, B.aspx and C.aspx use this master page. I can think of 2 alternatives when building this Menu Items: 1st > I set the url attribute like AAA > url="~/A.aspx" and similar to the other menu items ... so when I click in any of these menu items I´ll be directed to the respective url or 2nd > I don´t use the url attribute and catch the OnMenuItemClick event and then create code to switch to the proper url Since I´m using Tabs, it would be nice to set the 'Active or Selected' Tab after the user clicks it. In the 2nd approach I can set the e.Item.Selected = true; but the Css used to mark the selected item will not work because after the click, the current page will be redirected to the proper page and the selected item will not be selected anymore. So I´ll have to end up creating complex code just to mark the selected item, probably in the current page (A,B or C.aspx) referencing the Menu control in the master page. I believe there is a simple approach to this situation. What is the best way to set the selected/active tab? This is not hard when using plain html pages, but this master/content page relation are a bit confusing ... I already read this interesting article: http://www.dotnetslackers.com/XML/re-27950\_Capture\_Master\_Page\_Events\_in\_Content\_Pages\_ASP\_NET\_2\_0.aspx, but I think there must have a simple approach to this situation which unfortunately I just don´t get.
Because you go from the current page to a new one when a menu item is clicked, so the ViewState of the selected item gets lost, and IMO you may only need to write code in the Master Page to set the selected item of the menu control. All three pages use the same Master Page, so you don't need to write code to set the selected menu item in each web page. Another option might be that you can use a single web page instead of 3, and because you don't go to the new page so the selected menu item is persisted.
-
Because you go from the current page to a new one when a menu item is clicked, so the ViewState of the selected item gets lost, and IMO you may only need to write code in the Master Page to set the selected item of the menu control. All three pages use the same Master Page, so you don't need to write code to set the selected menu item in each web page. Another option might be that you can use a single web page instead of 3, and because you don't go to the new page so the selected menu item is persisted.
Hi minhpc_bk, You pointed 2 options: 1st: the one I´m using,eg navigating from current page to another, but with this option as you said, the ViewState of the selected item gets lost. What´s the solution for this option? Considering I want to navigate from one page to another ... Will I have to target the master page menu from each of the pages? That´s not a good solution ... too much coding 2nd: To use a single web page instead of 3, but this way I believe I´ll have to have views/panels hidden and showed according to the selected tab, right? This turn to concentrating too much logic in a single page. Suppose I have 100 tabs!!!
-
Hi minhpc_bk, You pointed 2 options: 1st: the one I´m using,eg navigating from current page to another, but with this option as you said, the ViewState of the selected item gets lost. What´s the solution for this option? Considering I want to navigate from one page to another ... Will I have to target the master page menu from each of the pages? That´s not a good solution ... too much coding 2nd: To use a single web page instead of 3, but this way I believe I´ll have to have views/panels hidden and showed according to the selected tab, right? This turn to concentrating too much logic in a single page. Suppose I have 100 tabs!!!
Sohdubom wrote:
What´s the solution for this option? Considering I want to navigate from one page to another ... Will I have to target the master page menu from each of the pages? That´s not a good solution ... too much coding
Because you define the menu control in the Master Page and all the web pages use this Master Page, so I think you only need to write code to set the selected menu item in the master page only and no need to do that from each content page. For example, you have 3 web pages A.aspx, B.aspx, C.aspx and the menu control in the master page is defined with 3 items accordingly. At run time you can detect the url of the current requested page by checking the Request object or SiteMap (if you define web.sitemap file), you then can set the Selected propety of the right menu item. The sample code to select the menu item in the master page looks something like:
//You can either use the Request object or SiteMap to determine
//the current url.
//string url = SiteMap.CurrentNode.Url;
string url = Request.Url.AbsoluteUri;if (url.Contains("A.aspx"))
Menu1.Items[0].Selected = true;
else if(url.Contains("B.aspx"))
Menu1.Items[1].Selected = true;
else
Menu1.Items[2].Selected = true;Sohdubom wrote:
To use a single web page instead of 3, but this way I believe I´ll have to have views/panels hidden and showed according to the selected tab, right? This turn to concentrating too much logic in a single page. Suppose I have 100 tabs!!!
You're right, this option should only be used when you have just a few web pages.