Need help modifying some existing code

alicia1234
alicia1234 used Ask the Experts™
on
I am new to this although I am experienced in other programming languages. I am trying to modify some existing code.

I want to make the <title> metatag in my page templates dynamic.

Master page is Coremaster.master.
So, for example, I have:
Coremaster.master
Coremaster.master.cs
and then
ThreeColumnLeftMenu.aspx
ThreeColumnLeftMenu.aspx.vb

(Yes - master page code-behind is c-sharp, template is VB)

In CoreMaster.master, the <title> tag was hardcoded. I have replace that code with
<title><%=MyConstants.SiteName%></title>
and that works as it should.

However, in the ThreeColumnLeftMenu code-behind, I have access to another piece of information that I want to tack on to the title. That info is in the variable "HeadingTitle".

How do I tack that on to my existing title tag?

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
from the code behind use:

Page.Title = "xyz";

or var x = Page.Title;

Author

Commented:
I tried that but my codebehind isn't recognizing page.title - it's giving me an error. I did a similar thing in all of the C-sharp code behinds and it worked fine, but the same thing is not working in the vb pages. They must have been coded differently. See below for the vb code-behind. Could you tell me specifically what I need to do?
You can see I've tried with the "thisPBpage" thing.
I repeat - I'm new at this ... just looking for the solution at this point. Thanks.

Code-behind for ThreeColumnLeftMenu (see below)

Imports System
Imports System.Data
Imports System.Web.Security
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.Page  'A.Shea 1/30/2010
Imports Ektron.Cms.Widget
Imports Ektron.Cms
Imports Ektron.Cms.API
Imports Ektron.Cms.Common
Imports Ektron.Cms.Controls.CmsWebService
Imports Ektron.Cms.PageBuilder

Partial Class Three_Column_Left_Menu1
    Inherits Ektron.Cms.PageBuilder.PageBuilder

    Protected contentAPI As New Ektron.Cms.ContentAPI()
    Protected commonAPI As New Ektron.Cms.CommonApi()
    'Protected thisPBpage As New System.Web.UI.Page() 'A.Shea 1/30/2010


    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Utilities.RegisterBaseUrl(Me.Page)
        RegisterJs()
        If (Not contentAPI.IsLoggedIn) Then
            Dim sitePath As String = contentAPI.SitePath.TrimEnd("/")
            Response.Redirect(sitePath & "/default.aspx")
            'Me.Page.ClientScript.RegisterStartupScript(Me.Page.GetType(), "get_script", "$ektron('#loginDialog').modal().modalShow();", True)
        End If

        FillMenu()

    End Sub

    Private Sub FillMenu()
        Dim cmonApi As New CommonApi()
        If cmonApi.IsLoggedIn Then
            If cmonApi.UserId > 0 Then
                Dim user As New Ektron.Cms.API.User.User()
                Dim utype As [String] = Nothing

                If Session("utype") IsNot Nothing Then
                    utype = Session("utype").ToString()
                If utype = "Executives" Then
                        fm2.DefaultMenuID = EktConstants.ExecutivesMID
                    ElseIf utype = "Employees" Then
                        fm2.DefaultMenuID = EktConstants.EmployeesMID
                    Else
                        fm2.DefaultMenuID = EktConstants.FreemiumMID
                End If
                Else
                    utype = "Freemium"
                    If user.IsAGroupMember(cmonApi.UserId, EktConstants.ExecutivesGID) OrElse user.MemberType = 0 Then
                        fm2.DefaultMenuID = EktConstants.ExecutivesMID
                        utype = "Executives"
                    ElseIf user.IsAGroupMember(cmonApi.UserId, EktConstants.EmployeesGID) Then
                        fm2.DefaultMenuID = EktConstants.EmployeesMID
                        utype = "Employees"
                    Else
                        fm2.DefaultMenuID = EktConstants.FreemiumMID
                    End If
                    Session("utype") = utype
                    fm2.Fill()
                End If
            End If
        End If
    End Sub

    Public Overloads Overrides Sub [Error](ByVal message As String)
        jsAlert(message)
    End Sub

    Public Overrides Sub Notify(ByVal message As String)
        jsAlert(message)
    End Sub

    Public Sub jsAlert(ByVal message As String)

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (Not String.IsNullOrEmpty(Request.QueryString("pageid"))) Then
            Dim pageid As Long = 0
            pageid = Long.Parse(Request.QueryString("pageid"))

            FolderBreadcrumb1.DefaultContentID = Long.Parse(Request.QueryString("pageid"))

            If ((pageid > 0) AndAlso (commonAPI.IsLoggedIn)) Then

                'get type
                Dim pagedata As Ektron.Cms.PageBuilder.PageData = Me.Pagedata '  Page as PageBuilder
                Dim thisPBpage As System.Web.UI.Page 'A. Shea 1/30/2010

                Dim contentdata As Ektron.Cms.ContentData = New Ektron.Cms.ContentData()
                pagedata.pageID = pageid
                hdnPageId.Value = pageid
                Dim metadata As Ektron.Cms.ContentMetaData() = Nothing
                contentdata.Id = pagedata.pageID

                Try
                    ' Sample below to retrieve the metadata value
                    'Dim cAPI As New Ektron.Cms.ContentAPI
                    'Dim att As Ektron.Cms.CustomAttributeList = cAPI.GetContentMetadataList(ID#)
                    'Dim IDList As String = att.GetItemByName("METADATANAME").Value

                    'A. Shea commented this out 1/30/2010 - this was a holdover from ELV that is no longer used; metadata is now retrieved
                    'by name
                    'contentdata.MetaData = contentAPI.GetMetaDataTypes("id")

                    Dim Metadatalist As Ektron.Cms.CustomAttributeList = contentAPI.GetContentMetadataList(pagedata.pageID)

                    'Metadata Values to retrieve:
                    '   PB Background Class   	    120
                    '   PB Heading Image 	        118
                    '   PB Heading Title 	        119
                    Dim pbHeadingTitle As String = String.Empty
                    pbHeadingTitle = contentAPI.GetContentMetadataList(pagedata.pageID).GetItemByName("PB Heading Title").Value.ToString()

                    Dim pbHeadingImage As String = String.Empty
                    pbHeadingImage = contentAPI.GetContentMetadataList(pagedata.pageID).GetItemByName("PB Heading Image").Value.ToString()
                    Dim pbBackgroundClass As String = String.Empty
                    pbBackgroundClass = contentAPI.GetContentMetadataList(pagedata.pageID).GetItemByName("PB Background Class").Value.ToString()
                    'pbBackgroundClass = contentdata.MetaData.GetValue(120).ToString()
                    'contentAPI.GetContentMetadataList(pagedata.pageID).GetItemByName("PB Heading Title").Value.ToString()

                    If ((pbHeadingImage.Length > 0) AndAlso (Not pbHeadingImage = String.Empty)) Then
                        'lblHeaderIcon.Text = String.Format("<img src=""{0}"" alt=""Heading Icon"" />", pbHeadingImage)
                    End If

                    If ((pbHeadingTitle.Length > 0) AndAlso (Not pbHeadingTitle = String.Empty)) Then
                        lblHeaderTitle.Text = String.Format("<h1>{0}</h1>", pbHeadingTitle)
                        lblLeftMenuTitle.Text = String.Format("<h3>{0}</h3>", pbHeadingTitle)
                        'A.Shea 1/30/2010
                        thisPBpage.Title = EktConstants.SiteName + pbHeadingTitle

                    End If

                    If ((pbBackgroundClass.Length > 0) AndAlso (Not pbBackgroundClass = String.Empty)) Then
                        hdnBackgroundClass.Value = pbBackgroundClass
                    End If
                Catch ex As Exception

                End Try

            End If

        End If

    End Sub

    Private Sub RegisterJs()

        'Register CCA Global JavaScript files
        Dim appPath As String = contentAPI.ApplicationPath.TrimEnd("/")
        Dim sitePath As String = contentAPI.SitePath.TrimEnd("/")
        Ektron.Cms.API.JS.RegisterJS(Me, JS.ManagedScript.EktronJS)
        Ektron.Cms.API.JS.RegisterJS(Me, sitePath & "/js/PBTemplateFunctions.js", "PBThreeColumnPageJS")

    End Sub

End Class

Open in new window

Author

Commented:
Note: I should also add that I would prefer to set the title tag in the ThreeColumnLeftMenu template and NOT in the master page. That would be ideal.
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Author

Commented:
In the code I posted, just search for "Shea" to find what I tried ...

Author

Commented:
OK, I got this working. What was missing was Title="something" in the page directive in the .aspx file. Once I added that, then Page.Title worked just fine.
Thanks.
ok, well done

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial