Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. asp:Menu select based on URL

asp:Menu select based on URL

Scheduled Pinned Locked Moved .NET (Core and Framework)
help
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    byka
    wrote on last edited by
    #1

    I am trying to select menu Items if based on url. below is my code and its not working, Please help

    Dim strFilePath As String = Me.Context.Request.FilePath
    If (strFilePath.Contains(strFilePath.IndexOf("/Groups.aspx").ToString)) = True Then
    Menu2.Items(0).Selected = True
    ElseIf (strFilePath.Contains(strFilePath.IndexOf("/Reports.aspx").ToString)) = True Then
    Menu2.Items(2).Selected = True
    Menu2.Items(0).Selected = False
    Else : Menu2.Items(0).Selected = False

        End If
    
    L M 2 Replies Last reply
    0
    • B byka

      I am trying to select menu Items if based on url. below is my code and its not working, Please help

      Dim strFilePath As String = Me.Context.Request.FilePath
      If (strFilePath.Contains(strFilePath.IndexOf("/Groups.aspx").ToString)) = True Then
      Menu2.Items(0).Selected = True
      ElseIf (strFilePath.Contains(strFilePath.IndexOf("/Reports.aspx").ToString)) = True Then
      Menu2.Items(2).Selected = True
      Menu2.Items(0).Selected = False
      Else : Menu2.Items(0).Selected = False

          End If
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      IndexOf[^] returns a number. You are checking whether the string contains that number. I think you want to check whether the string contains the substring.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      B 1 Reply Last reply
      0
      • L Lost User

        IndexOf[^] returns a number. You are checking whether the string contains that number. I think you want to check whether the string contains the substring.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        B Offline
        B Offline
        byka
        wrote on last edited by
        #3

        Here is my adjustments but it still not working

        Dim strFilePath As String = Me.Context.Request.FilePath
        If (strFilePath.Contains("/Groups.aspx")) = True Then
        Menu2.Items(0).Enabled = True
        ElseIf (strFilePath.Contains("/Reports.aspx")) = True Then
        Menu2.Items(2).Enabled = True
        Menu2.Items(0).Enabled = False
        Else
        Menu2.Items(0).Enabled = False
        End If

        Z 1 Reply Last reply
        0
        • B byka

          Here is my adjustments but it still not working

          Dim strFilePath As String = Me.Context.Request.FilePath
          If (strFilePath.Contains("/Groups.aspx")) = True Then
          Menu2.Items(0).Enabled = True
          ElseIf (strFilePath.Contains("/Reports.aspx")) = True Then
          Menu2.Items(2).Enabled = True
          Menu2.Items(0).Enabled = False
          Else
          Menu2.Items(0).Enabled = False
          End If

          Z Offline
          Z Offline
          ZurdoDev
          wrote on last edited by
          #4

          What does "not working" mean?

          There are only 10 types of people in the world, those who understand binary and those who don't.

          B 1 Reply Last reply
          0
          • Z ZurdoDev

            What does "not working" mean?

            There are only 10 types of people in the world, those who understand binary and those who don't.

            B Offline
            B Offline
            byka
            wrote on last edited by
            #5

            menu items not getting enabled

            Z 1 Reply Last reply
            0
            • B byka

              menu items not getting enabled

              Z Offline
              Z Offline
              ZurdoDev
              wrote on last edited by
              #6

              So what happens when you step through the code?

              There are only 10 types of people in the world, those who understand binary and those who don't.

              B 1 Reply Last reply
              0
              • Z ZurdoDev

                So what happens when you step through the code?

                There are only 10 types of people in the world, those who understand binary and those who don't.

                B Offline
                B Offline
                byka
                wrote on last edited by
                #7

                it will go to the correct if to enable the items however Item is not enabled on UI

                L P 2 Replies Last reply
                0
                • B byka

                  it will go to the correct if to enable the items however Item is not enabled on UI

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Add in some code to set the backgroundcolor of the control you're manipulating; that way you can check easily whether or not you're talking to the correct control, and whether all other code works. If it does, then there's a chance that the "enabled" property is being reset or overwritten by another part of the code.

                  Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                  1 Reply Last reply
                  0
                  • B byka

                    it will go to the correct if to enable the items however Item is not enabled on UI

                    P Offline
                    P Offline
                    Pete OHanlon
                    wrote on last edited by
                    #9

                    One thing to be aware of. You're doing a case sensitive comparison of a string there. What happens if the case doesn't match what you're testing for (hint, you won't trigger any of your enable conditions)?

                    1 Reply Last reply
                    0
                    • B byka

                      I am trying to select menu Items if based on url. below is my code and its not working, Please help

                      Dim strFilePath As String = Me.Context.Request.FilePath
                      If (strFilePath.Contains(strFilePath.IndexOf("/Groups.aspx").ToString)) = True Then
                      Menu2.Items(0).Selected = True
                      ElseIf (strFilePath.Contains(strFilePath.IndexOf("/Reports.aspx").ToString)) = True Then
                      Menu2.Items(2).Selected = True
                      Menu2.Items(0).Selected = False
                      Else : Menu2.Items(0).Selected = False

                          End If
                      
                      M Offline
                      M Offline
                      Member 9774039
                      wrote on last edited by
                      #10

                      put it in the PreRender funtion protected void Page_PreRender(object sender, EventArgs e) { Menu mymenu = (Menu)Form.FindControl("Menu1"); MenuItem mi = mymenu.FindItem("Programs"); mi.Selected = true; }

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups