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. Web Development
  3. ASP.NET
  4. Help for right syntax in .net for defining variables in web pages

Help for right syntax in .net for defining variables in web pages

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nethelp
5 Posts 3 Posters 1 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.
  • U Offline
    U Offline
    User 2512513
    wrote on last edited by
    #1

    I am trying to create a website in asp.net with multiple navigations links. A sample of the same in .asp is: Define a variable on the homepage: <% Dim varSection varSection = Request.Form("varSection") If varSection = "" Then varSection = "Home" End If%> And then call frm an include file as: <% If varSection = "Home" Then %> Display this content <% End If %> <% If varSection = "Abt" Then %> Display this content <% End If %> Likewise, I seek help with the right syntax in asp.net as above. Currently my homepage in asp.net just has the following code: <%@ Register TagPrefix="MY" TagName="top" src="includes/top.ascx"%> <%@ Register TagPrefix="Page" TagName="left" src="includes/left.ascx"%> <%@ Register TagPrefix="Header" TagName="right" src="includes/right.ascx"%> <%@ Register TagPrefix="Hdr" TagName="bottom" src="includes/bottom.ascx"%>

    D G 2 Replies Last reply
    0
    • U User 2512513

      I am trying to create a website in asp.net with multiple navigations links. A sample of the same in .asp is: Define a variable on the homepage: <% Dim varSection varSection = Request.Form("varSection") If varSection = "" Then varSection = "Home" End If%> And then call frm an include file as: <% If varSection = "Home" Then %> Display this content <% End If %> <% If varSection = "Abt" Then %> Display this content <% End If %> Likewise, I seek help with the right syntax in asp.net as above. Currently my homepage in asp.net just has the following code: <%@ Register TagPrefix="MY" TagName="top" src="includes/top.ascx"%> <%@ Register TagPrefix="Page" TagName="left" src="includes/left.ascx"%> <%@ Register TagPrefix="Header" TagName="right" src="includes/right.ascx"%> <%@ Register TagPrefix="Hdr" TagName="bottom" src="includes/bottom.ascx"%>

      D Offline
      D Offline
      Dinesh Mani
      wrote on last edited by
      #2

      You can do it in many ways, the simplest would be to do it with javascript. Just add the contents in div tags, set the display property on the click of the links using javascript.

      U 1 Reply Last reply
      0
      • U User 2512513

        I am trying to create a website in asp.net with multiple navigations links. A sample of the same in .asp is: Define a variable on the homepage: <% Dim varSection varSection = Request.Form("varSection") If varSection = "" Then varSection = "Home" End If%> And then call frm an include file as: <% If varSection = "Home" Then %> Display this content <% End If %> <% If varSection = "Abt" Then %> Display this content <% End If %> Likewise, I seek help with the right syntax in asp.net as above. Currently my homepage in asp.net just has the following code: <%@ Register TagPrefix="MY" TagName="top" src="includes/top.ascx"%> <%@ Register TagPrefix="Page" TagName="left" src="includes/left.ascx"%> <%@ Register TagPrefix="Header" TagName="right" src="includes/right.ascx"%> <%@ Register TagPrefix="Hdr" TagName="bottom" src="includes/bottom.ascx"%>

        G Offline
        G Offline
        Gregory Gadow
        wrote on last edited by
        #3

        As Dinesh said, there are many ways to do this. Unless design considerations make it too difficult, my preference is to use HyperLink controls on the page and set their properties in the page's PreRender event:

        Protected Sub Page_PreRender(ByVal sender As Object, _
        ByVal e As System.EventArgs)
        Dim varSection As String = Request.Form("varSection")

        Select Case varSection
            Case "Home"
                With Link1
                    .NavigateUrl = "Go here"
                    .Text = "Home"
                    .ToolTip = "Go Home"
                End With
                Link2.Visible = False
                Link3.Visible = False
        
             Case "Abt" 
                'Etc.
        End Select
        

        End Sub

        Another way of doing it would be to put static links on Panel controls, with only one visible depending on the value of varSection. When the page gets rendered, controls with no visibility are not added to the output stream so you don't need to worry about adding bloat. Can't help you with @Register as I've never had to use it. Our registration info is in web.config.

        U 1 Reply Last reply
        0
        • D Dinesh Mani

          You can do it in many ways, the simplest would be to do it with javascript. Just add the contents in div tags, set the display property on the click of the links using javascript.

          U Offline
          U Offline
          User 2512513
          wrote on last edited by
          #4

          Thanks Dinesh for the reply. It would be really helpful if you can provide me with a sample code in review of the .asp code I submitted. I am a just a newbie & not well-versed with the correct syntax.

          1 Reply Last reply
          0
          • G Gregory Gadow

            As Dinesh said, there are many ways to do this. Unless design considerations make it too difficult, my preference is to use HyperLink controls on the page and set their properties in the page's PreRender event:

            Protected Sub Page_PreRender(ByVal sender As Object, _
            ByVal e As System.EventArgs)
            Dim varSection As String = Request.Form("varSection")

            Select Case varSection
                Case "Home"
                    With Link1
                        .NavigateUrl = "Go here"
                        .Text = "Home"
                        .ToolTip = "Go Home"
                    End With
                    Link2.Visible = False
                    Link3.Visible = False
            
                 Case "Abt" 
                    'Etc.
            End Select
            

            End Sub

            Another way of doing it would be to put static links on Panel controls, with only one visible depending on the value of varSection. When the page gets rendered, controls with no visibility are not added to the output stream so you don't need to worry about adding bloat. Can't help you with @Register as I've never had to use it. Our registration info is in web.config.

            U Offline
            U Offline
            User 2512513
            wrote on last edited by
            #5

            Thanks Greg. From my query i initially submitted, I am looking out for a similar logic towards wht you stated @ putting static links on Panel controls & toggling b/w on-off visibility. Request you to provide with the correct syntax of the code to be used.

            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