1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

ASP Includes and Rollover Links???

Discussion in 'C#' started by jiggawattjoseph, May 16, 2006.

  1. #1
    Hi, I have built a site which uses ASP include statements to link to my navigation links. I have CSS "block" rollovers which I am very happy with. However, I need a way to denote which page the user is on in the navigation bar. Preferably, I would like to make the text bold for that link or something similar.

    The purpose of the include is to make editing the links easier for me (ie: I don't have to edit 50 individual documents), but in doing this, I have made it difficult to single out any of these links.

    I am thinking that because each page has a unique filename, which is displayed in the toolbar, perhaps I could write a script which pulls that info, compares it to the list of links and highlights the one it matches. However, from there, I am lost.

    A) is that the best way to complete this task?
    B) how would you do that/tutorials/example sites?
    C) if there is a better way, how would it be done?

    -jiggawattjoseph.
     
    jiggawattjoseph, May 16, 2006 IP
  2. DanInManchester

    DanInManchester Active Member

    Messages:
    116
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #2
    There are a number of ways to approach this....

    You could get your menu script to parse the folder path and or file name to determine the location and set the css style to bold accordingly.

    You could manually pass a variable to the include file to 'tell it' what are you are in.

    e.g.

    strSection = "FORUMS"
    <!--#include virtual="/includes/header.aspx" -->

    your include would then use strSection.

    alternatively and the way I often work on larger sites is to use a database. as the structure is hierarchical and the content stored in a database it is easy to pinpoint where you are in the site based on the database data.
     
    DanInManchester, May 16, 2006 IP
  3. jiggawattjoseph

    jiggawattjoseph Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hmmm... I like the part about passing a variable to the include file. How exactly would this work? Keep in mind I am not a programmer.

    This code would be unique to each page
    strSection = "FORUMS"
    <!--#include virtual="/includes/header.aspx" -->

    Then in my include file, I would have a line for each link like
    if strSection = "FORUMS"
    then <a href="forums.asp">[makeBold(FORUMS)]</a>;
    else
    <a href="forums.asp">FORUMS</a>

    Sorry, about the notation, I know its wrong. Just trying to get an idea of how this should work.
     
    jiggawattjoseph, May 16, 2006 IP
  4. DanInManchester

    DanInManchester Active Member

    Messages:
    116
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #4
    Yes you're on the right lines.

    I'd have an include file like this assuming we are using CSS styles....

    <%
    Sub WriteMenuStyle(Section)
        If Ucase(Section) = Ucase(strSection)
             response.write "MenuItemSelected"
        else
             response.write = "MenuItem"
        end if
    End Function
    %>
    <a href="forum.asp" Class="<% WriteMenuStyle("FORUMS") %>">
    Formums</a>
    <a href="faq.asp" Class="<% WriteMenuStyle("FAQ") %>">
    FAQ</a>
    <a href="Articles.asp" Class="<% WriteMenuStyle("ARTICLES") %>">
    Articles</a>
    Code (markup):
    So what this is doing is using your strSection that you passed in and comparing it to the current section you are requesting the style for. If it is the selected item then it writes out the selected style name otherwise it uses the default menu item style.

    Hope that makes sense!
     
    DanInManchester, May 16, 2006 IP
  5. vectorgraphx

    vectorgraphx Guest

    Messages:
    545
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Dan, this looks like a sensible approach. Nice work. Just leaves the user with the task of coming up with a way to grab and allocate the "strSection" variable... which can either be passed and grabbed via a querystring or done away with entirely by using the request.servervariables("url") variable:

    
    Sub WriteMenuStyle(Section)
        If Ucase(Section) = Ucase(Request.ServerVariables("url"))
             response.write "MenuItemSelected"
        else
             response.write = "MenuItem"
        end if
    End Function
    %>
    <a href="forum.asp" Class="<% WriteMenuStyle("/FORUMS/") %>">
    Formums</a>
    <a href="faq.asp" Class="<% WriteMenuStyle("/FAQ.asp") %>">
    FAQ</a>
    <a href="Articles.asp" Class="<% WriteMenuStyle("/ARTICLES.asp") %>">
    Articles</a>
    
    Code (markup):
    just food for thought :)
     
    vectorgraphx, May 17, 2006 IP
  6. DanInManchester

    DanInManchester Active Member

    Messages:
    116
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #6
    strSection would be passed in by the page including the file

    strSection = "FORUMS"
    <!--#include virtual="/includes/header.aspx" -->

    but it could be derived a number of ways.
     
    DanInManchester, May 17, 2006 IP
  7. jiggawattjoseph

    jiggawattjoseph Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Okay, so this is probably a newbie question. However...

    When I try to implement this, I get a HTTP 500 error. Perhaps I'm not entering in all the info I need.

    Any ideas...

    I know this is a broad one.
     
    jiggawattjoseph, May 19, 2006 IP
  8. DanInManchester

    DanInManchester Active Member

    Messages:
    116
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #8
    can you get the full error message.
    You may need to turn off friendly error messages in internet explorer options in order to get it.
     
    DanInManchester, May 19, 2006 IP
  9. MrWize

    MrWize Peon

    Messages:
    54
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    The error is "obvious" for a programmer.

    First, You create a Sub ... but never close it as "a sub". Instead, the statement looks like: End Function. Change it to - End Sub ... then You get rid of hte 500-message

    Sub WriteMenuStyle(Section)
    If Ucase(Section) = Ucase(Request.ServerVariables("url"))
    response.write "MenuItemSelected"
    else
    response.write = "MenuItem"
    end if
    End Sub

    cya,
    /PatrikB
     
    MrWize, May 20, 2006 IP
  10. DanInManchester

    DanInManchester Active Member

    Messages:
    116
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #10
    oh yeah sorry my mistake.

    I was gonna write it as a function call to return the string but then decided just to have the sub write out the content.

    It's still a good idea to turn off friendly error messages so you can debug your code more easily. Other wise you just get the meaningless 500 server error which doesn't tell you much.
     
    DanInManchester, May 20, 2006 IP
  11. jiggawattjoseph

    jiggawattjoseph Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Okay, so if you use 'End Sub' instead of end function here's what you get:

    If the WriteMenuStyle procedure is in the INC file, you get a http 500 error.

    However, if I put the WriteMenuStyle procedure into the ASP document, I get this:

    TYPE MISMATCH:'WriteMenuStyle'

    /BOTTOM.INC Line 17

    Line 17 of bottom.inc is this:
    <li><a href="ppr_beltlines.asp" Class="<% WriteMenuStyle("BELT-LINES") %>"><span id="small">Belt Lines</span></a></li>

    I am thinking that WriteMenuStyle isn't outputting as a string.
     
    jiggawattjoseph, May 22, 2006 IP
  12. DanInManchester

    DanInManchester Active Member

    Messages:
    116
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #12
    If you are making writemenustyle a function to return a string do it like this :


    <%
    Function WriteMenuStyle(Section)
        If Ucase(Section) = Ucase(strSection)
             WriteMenuStyle = "MenuItemSelected"
        else
             WriteMenuStyle = "MenuItem"
        end if
    End Function
    %>
    <a href="forum.asp" Class="<% = WriteMenuStyle("FORUMS") %>">
    Formums</a>
    <a href="faq.asp" Class="<% = WriteMenuStyle("FAQ") %>">
    FAQ</a>
    <a href="Articles.asp" Class="<% = WriteMenuStyle("ARTICLES") %>">
    Articles</a>
    Code (markup):
    A function returns a value so we have made the style funtion return the style name. therefore we need to write it to the browser.

    you can use either
    = WriteMenuStyle("FAQ")
    or
    response.write(WriteMenuStyle("FAQ"))


    If you want a sub to do the write for you do this :

    <%
    Sub WriteMenuStyle(Section)
        If Ucase(Section) = Ucase(strSection)
             response.write "MenuItemSelected"
        else
             response.write = "MenuItem"
        end if
    End sub
    %>
    <a href="forum.asp" Class="<% WriteMenuStyle("FORUMS") %>">
    Formums</a>
    <a href="faq.asp" Class="<% WriteMenuStyle("FAQ") %>">
    FAQ</a>
    <a href="Articles.asp" Class="<% WriteMenuStyle("ARTICLES") %>">
    Articles</a>
    Code (markup):
    in this example you only call the method and the sub does the write.
     
    DanInManchester, May 22, 2006 IP