locked
Please somebody help me..... RRS feed

  • Question

  • User797919657 posted

     I have a website, linksys88.com designed for online free advertisments. with the power of asp.net, and the help of classified starter kit, i was able to run and designed my site well. My problem is; the title tag of my showad.aspx page doesn't change to the title of the article / posting which was selected by the end user. To my best effort, I modified the Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) section of my showad.aspx.vb by adding Page.Title = Title + "-" + AdTitleLabel.Text. Now what happens is that, if you click any ads to my site the Main Title still remains the same, unless you click the picture of the selected the ads, the page title changes to Main Title including the title of the ads or article which was selected earlier. I tried other modifications but i really can't figure it out. What I really want is that upon clicking the ads on my site, the Page title of my showad.aspx page will automatically change or bind the ad title to main title. I got 97 pages indexed by google on one page title only which is sad. Please somebody help me figure this out. Thanks a lot in advance!!! and more power to ASP.Net experts!!! by the way, pardon me for, I am just a begginer on asp.net, although i am very willing to share any of my begginer ideas if there is anybody who is more begginer than me that is in need of reference. Thanks and God Bless!

    Saturday, April 11, 2009 11:36 AM

Answers

  • User730446648 posted

    You are very close.
    I had quite a run around to get it right but you need Me.Page.Title

    So here's what I did.
    I have set this code before in the page_load section on other pages.
    But in your specific case of the showad page I inserted the code (vb) into the AdDetails_ItemDataBound section.

    Try this.

    First you should remove your hard coded title on the .aspx page.

    For example;
    Title="My Hard Coded Title"

    should become Title=""

    Now insert the code.

    Dim metaDescription As New HtmlMeta

    Dim MetaCount As Integer = ad.Description.Length

    Me.Page.Title = " For Rent " + StrConv(ad.Title, vbProperCase) + ", "

    metaDescription.Name = "description"

    If MetaCount <= 150 Then

    metaDescription.Content = ad.Description

    Else

    metaDescription.Content = ad.Description.ToString().Substring(0, 150)

    End If

    Page.Header.Controls.Add(metaDescription)

    That should work.

    As you can see I even included code to limit the description characters to 150 characters.

    Enjoy.

    - Daniel

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 11, 2009 12:24 PM
  • User730446648 posted

    You just put it in too early in the section.
    The app doesn't know what "ad" is until it's declared somewhere.

    Try pasting in my code after this:

    Dim item As RepeaterItem = e.Item
            Dim ad As AdsDataComponent.AdsRow = CType(item.DataItem, AdsDataComponent.AdsRow)
            If Not (ad Is Nothing) Then

     

    When writing code you have to think of it as a very specific map how to get somewhere.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 11, 2009 8:09 PM
  • User797919657 posted

     Sir Daniel,

    Thank you so much, It worked!!! and for me to learn my lesson, i didn't just paste your code, i debug my script and wrote it line by line, for me to deeply understand what you have taught me, and what's amazing is that, it has been fixed in a matter of 8 hours, where in fact i've been trying to worked this out in almost two weeks. ASP.net together with its professional GURU's like you sir Daniel is so powerful. It has so many ways and strategies in creating powerful websites.

     THanks Again Sir Daniel!!! and more power to you!!!! God Bless!!!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 11, 2009 9:14 PM

All replies

  • User730446648 posted

    You are very close.
    I had quite a run around to get it right but you need Me.Page.Title

    So here's what I did.
    I have set this code before in the page_load section on other pages.
    But in your specific case of the showad page I inserted the code (vb) into the AdDetails_ItemDataBound section.

    Try this.

    First you should remove your hard coded title on the .aspx page.

    For example;
    Title="My Hard Coded Title"

    should become Title=""

    Now insert the code.

    Dim metaDescription As New HtmlMeta

    Dim MetaCount As Integer = ad.Description.Length

    Me.Page.Title = " For Rent " + StrConv(ad.Title, vbProperCase) + ", "

    metaDescription.Name = "description"

    If MetaCount <= 150 Then

    metaDescription.Content = ad.Description

    Else

    metaDescription.Content = ad.Description.ToString().Substring(0, 150)

    End If

    Page.Header.Controls.Add(metaDescription)

    That should work.

    As you can see I even included code to limit the description characters to 150 characters.

    Enjoy.

    - Daniel

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 11, 2009 12:24 PM
  • User797919657 posted

     Hi Sir Daniel,

     That was a quick reply! You're great! although I encounter few errors, maybe i failed to do it right (kindly let me know where i made my mistake...[:$]) as per your instruction. Here's what happened when I followed revisions on my showad.aspx page and the code on showad.aspx.vb as per your recommendation:

    1. First you should remove your hard coded title on the .aspx page:

    Before:  <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" CodeFile="ShowAd.aspx.vb"
        Inherits="ShowAd_aspx" Title = "<strike>My Classified Ads | Buy | Sell | Trade | Jobs | Business | Rent | Lease | Room | Condominiums | House | Apartment | Auto | Cars | Services | Electronics | Gadgets | Music | Commmercial Spaces | Buildings</strike>" %>

    After:  <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" CodeFile="ShowAd.aspx.vb"
        Inherits="ShowAd_aspx" Title = "" %>

     

    2.  Now insert the code. I inserted the code (vb) into the AdDetails_ItemDataBound section - I did this on my showad.aspx.vb

    BEFORE: 

     Protected Sub AdDetails_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
     
            Dim item As RepeaterItem = e.Item
            Dim ad As AdsDataComponent.AdsRow = CType(item.DataItem, AdsDataComponent.AdsRow)
            If Not (ad Is Nothing) Then
                AdTitleLabel.Text = ad.Title
                AdPriceLabel.Text = String.Format("{0:c}", ad.Price)

                Dim ExpirationLabel As Label = CType(item.FindControl("ExpirationLabel"), Label)
                Dim URLLink As HyperLink = CType(item.FindControl("URLLink"), HyperLink)

                AdTypeLabel.Text = OutputFormatting.AdTypeToString(ad.AdType)

                If ad.URL.Equals(String.Empty) Then
                    URLLink.Text = "N/A"
                Else
                    URLLink.Text = ad.URL
                    URLLink.NavigateUrl = ad.URL
                    URLLink.Target = "_blank"
                End If

                If ad.IsExpirationDateNull() Then
                    ExpirationLabel.Text = "N/A"
                Else
                    ExpirationLabel.Text = String.Format("{0:D}", ad.ExpirationDate)
                End If

                If CType(ad.AdStatus, AdStatus) = AdStatus.Activated Then
                    If Profile.MemberId <> ad.MemberId Then
                        ' check if the user has recently viewed this page
                        ' by looking in a special cookie we set:
                        Dim adCookieKey As String = ad.Id.ToString()
                        If Request.Cookies("ShowAd_ViewCountCookie") Is Nothing OrElse Request.Cookies("ShowAd_ViewCountCookie")(adCookieKey) Is Nothing Then
                            Response.Cookies("ShowAd_ViewCountCookie")(adCookieKey) = String.Empty ' String.Empty is not treated as 'null' but saves a byte
                            Response.Cookies("ShowAd_ViewCountCookie").Expires = DateTime.Now.AddDays(1)
                            AdsDB.IncrementViewCount(ad.Id)
                        End If
                    End If
                Else
                    AdNotActivePanel.Visible = True
                    AdActions.Visible = False
                End If
            End If
        End Sub

     

    AFTER: (note, the bold letters is the set of script i copied and pasted) (the italic font is the error comment -)

    Protected Sub AdDetails_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
           

            Dim metaDescription As New HtmlMeta

            Dim MetaCount As Integer = ad.Description.Length
      -------------------------------I got an error saying: Local Variable 'ad' cannot be referred to before it is declared...
            Me.Page.Title = " For Rent " + StrConv(ad.Title, vbProperCase) + ", "  -------------------------------I got an error saying: Local Variable 'ad' cannot be referred to before it is declared...

            metaDescription.Name = "description"

            If MetaCount <= 150 Then

                metaDescription.Content = ad.Description   
    -------------------------------I got an error saying: Local Variable 'ad' cannot be referred to before it is declared...

            Else

                metaDescription.Content = ad.Description.ToString().Substring(0, 150)  
    -------------------------------I got an error saying: Local Variable 'ad' cannot be referred to before it is declared...

            End If

            Page.Header.Controls.Add(metaDescription)

       

            Dim item As RepeaterItem = e.Item
            Dim ad As AdsDataComponent.AdsRow = CType(item.DataItem, AdsDataComponent.AdsRow)
            If Not (ad Is Nothing) Then
                AdTitleLabel.Text = ad.Title
                AdPriceLabel.Text = String.Format("{0:c}", ad.Price)

                Dim ExpirationLabel As Label = CType(item.FindControl("ExpirationLabel"), Label)
                Dim URLLink As HyperLink = CType(item.FindControl("URLLink"), HyperLink)

                AdTypeLabel.Text = OutputFormatting.AdTypeToString(ad.AdType)

                If ad.URL.Equals(String.Empty) Then
                    URLLink.Text = "N/A"
                Else
                    URLLink.Text = ad.URL
                    URLLink.NavigateUrl = ad.URL
                    URLLink.Target = "_blank"
                End If

                If ad.IsExpirationDateNull() Then
                    ExpirationLabel.Text = "N/A"
                Else
                    ExpirationLabel.Text = String.Format("{0:D}", ad.ExpirationDate)
                End If

                If CType(ad.AdStatus, AdStatus) = AdStatus.Activated Then
                    If Profile.MemberId <> ad.MemberId Then
                        ' check if the user has recently viewed this page
                        ' by looking in a special cookie we set:
                        Dim adCookieKey As String = ad.Id.ToString()
                        If Request.Cookies("ShowAd_ViewCountCookie") Is Nothing OrElse Request.Cookies("ShowAd_ViewCountCookie")(adCookieKey) Is Nothing Then
                            Response.Cookies("ShowAd_ViewCountCookie")(adCookieKey) = String.Empty ' String.Empty is not treated as 'null' but saves a byte
                            Response.Cookies("ShowAd_ViewCountCookie").Expires = DateTime.Now.AddDays(1)
                            AdsDB.IncrementViewCount(ad.Id)
                        End If
                    End If
                Else
                    AdNotActivePanel.Visible = True
                    AdActions.Visible = False
                End If
            End If
        End Sub

    Is there anything wrong i've done sir? hope to hear again from you soon! God Bless! and thanks for sharing your knowldege and time...

    Saturday, April 11, 2009 4:02 PM
  • User730446648 posted

    You just put it in too early in the section.
    The app doesn't know what "ad" is until it's declared somewhere.

    Try pasting in my code after this:

    Dim item As RepeaterItem = e.Item
            Dim ad As AdsDataComponent.AdsRow = CType(item.DataItem, AdsDataComponent.AdsRow)
            If Not (ad Is Nothing) Then

     

    When writing code you have to think of it as a very specific map how to get somewhere.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 11, 2009 8:09 PM
  • User797919657 posted

     Sir Daniel,

    Thank you so much, It worked!!! and for me to learn my lesson, i didn't just paste your code, i debug my script and wrote it line by line, for me to deeply understand what you have taught me, and what's amazing is that, it has been fixed in a matter of 8 hours, where in fact i've been trying to worked this out in almost two weeks. ASP.net together with its professional GURU's like you sir Daniel is so powerful. It has so many ways and strategies in creating powerful websites.

     THanks Again Sir Daniel!!! and more power to you!!!! God Bless!!!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 11, 2009 9:14 PM