problem I am trying to solve

G

Gorge Lucas

Hi guys,

Using asp.net with c#.

I have a default master page which has the following:

<ul>
<li id="About" class="m1"><a href="About.aspx">About
us</a></li>
<li id="Services" class="m2"><a
href="Services.aspx">Services</a></li>
<li id="Solutions" class="m3"><a
href="Solutions.aspx">Solutions</a></li>
<li id="Support" class="m4"><a
href="Support.aspx">Support</a></li>
<li id="Contact" class="m5"><a
href="Contact.aspx">Contact</a></li>
</ul>

Now, how can I insert something in to this peice from the child pages? Like,
if someone clicks on services, I need to modify the the services bit:
<li id="Services" class="m2"><a href="Services.aspx"
class="CurrentMenu">Services</a></li>

So it adds the class="CurrentMenu". This is so I can have effects on each
menu... I cannot find an easy way to do this.

Suggestions?

Thanks
 
G

Guest

Hi guys,

Using asp.net with c#.

I have a default master page which has the following:

                <ul>
                    <li id="About" class="m1"><a href="About.aspx">About
us</a></li>
                    <li id="Services" class="m2"><a
href="Services.aspx">Services</a></li>
                    <li id="Solutions" class="m3"><a
href="Solutions.aspx">Solutions</a></li>
                    <li id="Support" class="m4"><a
href="Support.aspx">Support</a></li>
                    <li id="Contact" class="m5"><a
href="Contact.aspx">Contact</a></li>
                </ul>

Now, how can I insert something in to this peice from the child pages? Like,
if someone clicks on services, I need to modify the the services bit:
                  <li id="Services" class="m2"><a href="Services.aspx"
class="CurrentMenu">Services</a></li>

So it adds the class="CurrentMenu". This is so I can have effects on each
menu... I cannot find an easy way to do this.

Suggestions?

Thanks

If you have limited number of pages you can simply check the name of
content page and set style for the menu directly from the master page.
Here's short example

string p = Request.Url.Segments[1].ToLower().Replace("/",
string.Empty);
switch (p)
{
case "services.aspx":
menuId = "Services";
default:
menuId = "About";
break;
}

HtmlGenericControl li = (HtmlGenericControl)this.FindControl(menuId);
li.Attributes.Add("class", "CurrentMenu");

That's all,
 
G

Guest

Yes, but why reinvent the wheel when the <asp:Menu /> control does all of
this...?

I don't know why author is not using this but there are few reasons
not to do this: 1) SEO, 2) by default it does not work properly in IE8
3) table less design
 
G

Guest


I agree with you, you may fix everything. But making things simple is
not reinventing the wheel. Suppose, we have a 5 items menu, we have a
small project, and html design is already done. Why do I need to go
for an ASP.NET control if I can do everything on my own with just few
lines of code and no change in design layout? If you look at my
example you can see how easy to do the same thing without any
controls. You don't need XML map, adapters, server fix (huh!), etc...
nothing. The bad thing in my example is that you will be dependent on
the page names and css styling name rules. But is that really an
issue...? For many people and many projects it is not an issue.
Moreover, if you make it more universal, like the code below, you will
partly fix that issue

string menuId = Request.Url.Segments[1].ToLower().Replace("/",
string.Empty);
HtmlGenericControl li = (HtmlGenericControl)this.FindControl(menuId);
li.Attributes.Add("class", "CurrentMenu");

(in this case html must have naming as id="services" vs id="Services")

Note, there are just 3 lines of code... and it will do exactly the
same thing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top