October 2004 - Posts

asp:menu - mark the current tab selected

Using a new asp:menu control on a Whidbey master page. I'm treating the menu tab(items) as navigateUrls, and not as command postbacks. Originally, I added code for selecting the current menu item to each of the aspx pages that represent one of the navigateUrls of the menu tabs. The code would look something like this:

DirectCast(Me.Master.FindControl("MainMenu"), Menu).Items(0).Selected = True

Unfortunately, this meant that each aspx page that was navigated as part of the menu system would need to have knowledge of where in the menu it was located (i.e. items(i)). I didn't care for this approach because if I ever wanted to change the tab order of the menu, I would then need to touch each of the respective aspx pages to change this line.

The next thought I had was using configuration to control the ordinal in the items collection. So, I could add config keys like this:

<add key=MyMenu:MyPage value=0/>
<add key=MyMenu:MyOtherPage value=1/>

Then the line of code in each aspx page could be re-written as:

DirectCast(Me.Master.FindControl("MainMenu"), Menu).Items(GetConfig("MyPage")).Selected = True

Where GetConfig is just a method that gets this page's respective ordinal value from the configuration. This was better, but wasn't good enough. I really didn't want each page to even require this single line of code. The menu itself, or at least code on the page where the menu lives should be making this decision to mark a tab item as selected.

I then came up with an approach of adding the tab menu selection code directly to the master page that contains the menu. I added the following code to my master page:

Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
     Dim thisPage As String
     thisPage = Page.GetType.Name
     For Each item As MenuItem In DefaultMenu.Items
          If item.ValuePath = thisPage Then
              item.Selected = True
          Else
              item.Selected = False
          End If
     Next
End Sub

Now all the code to handle this is in one place, and its in a place that makes more sense; the master page that houses the asp:menu. In order to make this work, I simply add the class name of the page; i.e. MyPage_aspx as the menu items value (not it's navigate Url). I choose to not get involved with inspecting the url, because I didn't want to worry about redirects, transfers, or maybe some other tricks I'll need to use down the road that involve some behind the scenes url munging.

I kinda like this approach for now, it's simple, in one place, and the only responsibility to make it work lies with the process of adding menu items, which is where I think it should be.

Now, I'm waiting for somebody to post back, “hey, why didn't you just set the AutoSelectCurrentMenuTab property on the asp:menu control”. Unfortunately, if such a property exist I didn't know about it ;-)

whidbey beta and little sleep

finally got around to loading 2.0 beta last weekend...WOW! Between, whidbey and the ALC marathon series games this week, there has been little room for sleep. I know, I know, what has taken me so long to get around to looking at the beta.

The main reason for hesitating has to do with fearing the black hole, and after only a week I'm already caught in its gravitational pull. There's the day job paying project that is knee deep in good size 1.1 project that looks pretty busy right up until around 1st quarter 2005. I've loved working with .Net 1.x, and I feel I'm at a pretty good point with my 1.x knowledge base that I can be pretty productive with it. I've feared that if I betrayed my VS2003 IDE, by playing around with VS2005, it would be tough to look in her the eyes from 9-5. Well it's happened; and after only 1 week I think I'm in love.

Partial classes, generics, my., provider models, the new win controls, the new web controls...The day job is the day job, but I don't think I'll sleep much for a while with my new night time acquaintance; it's tough to live a double life.

 

Off topic – Why I hate ordering Sandwiches From Subway

OK, this is a bit off topic and pretty random, but for what its worth, I really hate ordering sandwiches for a group of people from Subway. My frustration usually begins around the time an eager clerk first asks, “what kind of roll(s) do you want”.

Generally when I draw the shortest straw and end up being the runner for sandwiches, the process begins by me asking everybody what they want. I end up with a list that might look something like this:

  • John: 12” Turkey, with cheese, mayo, lettuce and tomato, on a white roll
  • Bill: 6” Ham, no cheese, Italian dressing, all veggies on an Italian roll
  • Jill: 6” Turkey, cheese, on a Parmesan Italian roll, no dressing, lettuce, tomato, olives
  • Sally: 6” Italian Mix, cheese Italian dressing, all veggies on a Wheat roll
  • me: 12” Chicken Teriyaki, Italian roll, sweet onion dressing, all veggies (except hot peppers)

So, I walk up to the counter with my list in hand, and the clerk says “What kind of rolls can I get you?” Do you see the problem yet? Am I the only person in the world that thinks this is just plain wrong, or at least difficult from the customer’s perspective? Sure, it makes sense from the perspective of the Subway clerks to work in an assembly line like fashion, first get the rolls, then the cheese (where needed) then the meats, then the veggies, dressing, etc. But shouldn’t that translation from what I want to what they need be their problem, and not mine as a customer.

When I am placing my order I’m thinking what kind of subs I want for each person. I’m not thinking that I need 2 - 6” Italian rolls, 1 - 12” Italian roll, 1 - 6” Wheat roll and 1 – 12” White roll. Besides, do I say 2 – 6” Italian rolls and 1 – 12” Italian roll, or when I’m at the roll ordering point, do I just say 2 – 12” Italian rolls, and then straighten out the finer detail that one of those 12”ers is really 2 – 6” separate sandwiches when we get to the topping questions.

The problem only gets worse after we deal with the rolls. Because then the next question is “ do any of these have cheese”. Well, lets see, looking at my list, the 12” Turkey has cheese, so there is one yes to for cheese on the 12” white. The 6” Ham has no cheese, the 6” Turkey has cheese, so yes to cheese on one of the 6” Italian rolls, but not the other (we’ll need to make sure I keep track of which is which later on when I’m asked the meat questions.) The 6” Italian mix has cheese so, yes to cheese on the 6” wheat roll. The Chicken Teriyaki has no cheese, so no to cheese on the 12” Italian roll.

Now onto more fun, the meats. The clerk (sometimes the next clerk in the assembly line depending on how busy they are) asks, "what kind of meats do you want on these." Well let’s see: I need a 12” Turkey on white with cheese, so if you have a 12” White with cheese there, then that is the Turkey. I need a 6” Ham on an Italian roll without cheese, so if you have a 6” Italian roll without cheese, then that one is going to be a Ham. I need a 6” Turkey with cheese on an Itailian roll, so if you have an Italian roll there with cheese on it, then make that the Turkey… and so on and so on.

Why, oh why, can’t I just tell you what I want and be done with it. Maybe the first clerk could punch my order into a program that then sorts and orders each of the individual sandwich components for each of the individual assembly line clerks. Or maybe you can just be old fashion and write my order down, and then determine for yourself the quantities of each of the individual components.

Subway, if you don’t have a sandwich order component sorter program, I would be happy to write one for you. Just email me at scottpstewart@NOSPAM_hotmail.com. I would be happy to help you out in return for a lifetime supply of sandwiches. ;-)

Jarred, does it need to be this tough for a customer to simply order a few sandwiches?