Help for right syntax in .net for defining variables in web pages
-
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"%>
-
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"%>
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.
-
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"%>
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'sPreRender
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 ofvarSection
. 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 inweb.config
. -
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.
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.
-
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'sPreRender
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 ofvarSection
. 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 inweb.config
.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.