locked
Ads are being posted twice RRS feed

  • Question

  • User-706703781 posted

     Hi, when I go to post an ad on my site it appears twice. I can't even figure out what might be causing this. If you have any idea what is causing this or how to fix it please reply.

    Thanks

    Tuesday, March 16, 2010 12:13 PM

Answers

  • User-706703781 posted

    I fixed it! The problem was in the postad.aspx.vb file.

    Here' the fixed code (unmodified code from the starter kit)

    Imports System
    Imports System.Text
    Imports System.Web.Security
    Imports System.Web.UI.WebControls
    Imports System.Collections.Generic
    
    Imports AspNet.StarterKits.Classifieds.Web
    Imports AspNet.StarterKits.Classifieds.BusinessLogicLayer
    
    Partial Class PostAd_aspx
        Inherits System.Web.UI.Page
    
        Public Property PreviousAdId() As Integer
            Get
                If Not (ViewState("PreviousAdId") Is Nothing) Then
                    Return CInt(ViewState("PreviousAdId"))
                Else
                    Return 0
                End If
            End Get
            Set(ByVal value As Integer)
                ViewState("PreviousAdId") = value
            End Set
        End Property
    
        Public ReadOnly Property IsPreviousAd() As Boolean
            Get
                Return Not (ViewState("PreviousAdId") Is Nothing)
            End Get
        End Property
    
        Private Const OtherLocationText As String = "Other..."
    
        Protected Sub PostAdWizard_FinishButtonClick(ByVal sender As Object, ByVal e As WizardNavigationEventArgs)
            If Page.IsValid Then
                Dim memberId As Integer = Profile.MemberId
                Dim categoryId As Integer = CategoryPath.CurrentCategoryId
                Dim title As String = Server.HtmlEncode(TitleTextBox.Text)
                Dim description As String = Server.HtmlEncode(DescriptionTextBox.Text)
                Dim url As String = Server.UrlEncode(UrlTextBox.Text)
                Dim price As [Decimal] = [Decimal].Parse(PriceTextBox.Text)
    
                Dim location As String = Server.HtmlEncode(LocationDropDown.CurrentLocation)
    
                Dim numDays As Integer = Convert.ToInt32(NumDaysList.SelectedValue)
    
                Dim adType As AdType = adType.ForSale
    
                If [Enum].IsDefined(GetType(AdType), Convert.ToInt32(AdTypeSelection.SelectedValue)) Then
                    adType = CType([Enum].Parse(GetType(AdType), AdTypeSelection.SelectedValue), AdType)
                End If
                If IsPreviousAd Then
                    AdsDB.RelistAd(PreviousAdId, categoryId, title, description, url, price, location, numDays, AdLevel.Unspecified, AdStatus.Unspecified, adType)
    
                    Response.Redirect("~/MyAds.aspx", True)
    
                Else
                    Dim adId As Integer = AdsDB.InsertAd(memberId, categoryId, title, description, url, price, location, numDays, AdLevel.Unspecified, AdStatus.Unspecified, adType)
    
                    Dim s As SiteSettings = SiteSettings.GetSharedSettings()
                    UploadImagesLink.Visible = s.AllowImageUploads
                    UploadImagesLink.NavigateUrl = "~/ManagePhotos.aspx?id=" + adId.ToString()
                End If
    
            Else
                e.Cancel = True
            End If
        End Sub
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    
            ' Limit Description text.
            DescriptionTextBox.Attributes.Add("onkeydown", "textCounter(this,500);")
            DescriptionTextBox.Attributes.Add("onkeyup", "textCounter(this,500);")
    
            If Not Page.IsPostBack Then
    
                PostAdWizard.MoveTo(PostAdWizard.WizardSteps(0))
    
                Dim qsRelistId As String = Request.QueryString("relist")
                If Not (qsRelistId Is Nothing) Then
                    Dim adId As Integer
                    If Int32.TryParse(qsRelistId, adId) Then
                        LoadPreviousAd(adId)
                    End If
                End If
            End If
        End Sub
    
        Protected Sub LoadPreviousAd(ByVal adId As Integer)
            Dim ad As AdsDataComponent.AdsRow = AdsDB.GetAdById(adId)
            If Not (ad Is Nothing) Then
                If ad.MemberId = Profile.MemberId Then
                    PreviousAdId = adId
    
                    SetCurrentCategory(ad.CategoryId)
    
                    If CType(ad.AdType, AdType) = AdType.Wanted Then
                        AdTypeSelection.SelectedIndex = 1
                    Else
                        AdTypeSelection.SelectedIndex = 0
                    End If
                    TitleTextBox.Text = ad.Title
                    DescriptionTextBox.Text = ad.Description
                    UrlTextBox.Text = ad.URL
                    LocationDropDown.CurrentLocation = ad.Location
                End If
            End If
        End Sub
    
    
        Protected Sub UpdateCategoryDisplay()
            Me.CategoryPathLabel.Text = CategoryPath.FullCategoryPath
        End Sub
    
    
        Protected Sub SubcategoriesDS_Selected(ByVal sender As Object, ByVal e As ObjectDataSourceStatusEventArgs)
            Dim subCategories As List(Of CachedCategory) = CType(e.ReturnValue, List(Of CachedCategory))
            If subCategories Is Nothing OrElse subCategories.Count = 0 Then
                PostAdWizard.MoveTo(PostAdWizard.WizardSteps(1))
            End If
        End Sub
    
    
        Protected Sub SetCurrentCategory(ByVal categoryId As Integer)
            CategoryPath.CurrentCategoryId = categoryId
            UpdateCategoryDisplay()
        End Sub
    
    
        Protected Sub SubcategoriesList_ItemCommand(ByVal [source] As Object, ByVal e As DataListCommandEventArgs)
            Dim categoryId As Integer = Convert.ToInt32(e.CommandArgument)
            SetCurrentCategory(categoryId)
        End Sub
    
    
        Protected Sub CategoryPath_CategorySelectionChanged(ByVal sender As Object, ByVal e As CategorySelectionChangedEventArgs)
            UpdateCategoryDisplay()
        End Sub
    
    
        Protected Sub ChangeCategoryButton_Click(ByVal sender As Object, ByVal e As EventArgs)
            SetCurrentCategory(DefaultValues.CategoryIdMinValue)
            PostAdWizard.MoveTo(PostAdWizard.WizardSteps(0))
        End Sub
    
        Protected Sub PostAdWizard_PreviousButtonClick(ByVal sender As Object, ByVal e As WizardNavigationEventArgs)
            If e.NextStepIndex = 0 Then
                SetCurrentCategory(DefaultValues.CategoryIdMinValue)
            End If
        End Sub
    
        Protected Sub ValidLocationRequired_ServerValidate(ByVal [source] As Object, ByVal args As ServerValidateEventArgs)
            args.IsValid = Not LocationDropDown.CurrentLocation.Equals(String.Empty)
        End Sub
    
        Protected Sub PriceValidator_ServerValidate(ByVal [source] As Object, ByVal args As ServerValidateEventArgs)
            Dim p As Decimal = -1
            If Decimal.TryParse(PriceTextBox.Text, p) Then
                args.IsValid = p >= 0
            Else
                args.IsValid = False
            End If
        End Sub
        Protected Sub URLValidator_ServerValidate(ByVal [source] As Object, ByVal args As ServerValidateEventArgs)
    
            args.IsValid = False
            Dim URLTextBox As TextBox = CType(AdDetailsStep.FindControl("UrlTextBox"), TextBox)
            If Not (URLTextBox Is Nothing) AndAlso Not (URLTextBox.Text.Equals(String.Empty)) Then
                Try
                    Dim uri As New Uri(URLTextBox.Text)
                    If (uri.IsWellFormedOriginalString() And _
                    (uri.Scheme = "http" Or uri.Scheme = "https")) Then
                        args.IsValid = True
                    End If
    
                Catch ex As Exception
    
                End Try
    
            Else
                ' Empty URL is okay.
                args.IsValid = True
            End If
    
        End Sub
    End Class


     

     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 16, 2010 3:37 PM

All replies

  • User1011739529 posted

    Hi,

    Would you please copy your code so we can check it out for any possible problem? 

    Tuesday, March 16, 2010 1:22 PM
  • User-706703781 posted

    What code do you need to see?  

    Tuesday, March 16, 2010 1:27 PM
  • User1011739529 posted

    Have you used asp:adrotator control to show your ads? 

    Tuesday, March 16, 2010 1:39 PM
  • User-706703781 posted

    No, I have not used asp:adrotator control to show any ads.

    Tuesday, March 16, 2010 1:42 PM
  • User-706703781 posted

    I fixed it! The problem was in the postad.aspx.vb file.

    Here' the fixed code (unmodified code from the starter kit)

    Imports System
    Imports System.Text
    Imports System.Web.Security
    Imports System.Web.UI.WebControls
    Imports System.Collections.Generic
    
    Imports AspNet.StarterKits.Classifieds.Web
    Imports AspNet.StarterKits.Classifieds.BusinessLogicLayer
    
    Partial Class PostAd_aspx
        Inherits System.Web.UI.Page
    
        Public Property PreviousAdId() As Integer
            Get
                If Not (ViewState("PreviousAdId") Is Nothing) Then
                    Return CInt(ViewState("PreviousAdId"))
                Else
                    Return 0
                End If
            End Get
            Set(ByVal value As Integer)
                ViewState("PreviousAdId") = value
            End Set
        End Property
    
        Public ReadOnly Property IsPreviousAd() As Boolean
            Get
                Return Not (ViewState("PreviousAdId") Is Nothing)
            End Get
        End Property
    
        Private Const OtherLocationText As String = "Other..."
    
        Protected Sub PostAdWizard_FinishButtonClick(ByVal sender As Object, ByVal e As WizardNavigationEventArgs)
            If Page.IsValid Then
                Dim memberId As Integer = Profile.MemberId
                Dim categoryId As Integer = CategoryPath.CurrentCategoryId
                Dim title As String = Server.HtmlEncode(TitleTextBox.Text)
                Dim description As String = Server.HtmlEncode(DescriptionTextBox.Text)
                Dim url As String = Server.UrlEncode(UrlTextBox.Text)
                Dim price As [Decimal] = [Decimal].Parse(PriceTextBox.Text)
    
                Dim location As String = Server.HtmlEncode(LocationDropDown.CurrentLocation)
    
                Dim numDays As Integer = Convert.ToInt32(NumDaysList.SelectedValue)
    
                Dim adType As AdType = adType.ForSale
    
                If [Enum].IsDefined(GetType(AdType), Convert.ToInt32(AdTypeSelection.SelectedValue)) Then
                    adType = CType([Enum].Parse(GetType(AdType), AdTypeSelection.SelectedValue), AdType)
                End If
                If IsPreviousAd Then
                    AdsDB.RelistAd(PreviousAdId, categoryId, title, description, url, price, location, numDays, AdLevel.Unspecified, AdStatus.Unspecified, adType)
    
                    Response.Redirect("~/MyAds.aspx", True)
    
                Else
                    Dim adId As Integer = AdsDB.InsertAd(memberId, categoryId, title, description, url, price, location, numDays, AdLevel.Unspecified, AdStatus.Unspecified, adType)
    
                    Dim s As SiteSettings = SiteSettings.GetSharedSettings()
                    UploadImagesLink.Visible = s.AllowImageUploads
                    UploadImagesLink.NavigateUrl = "~/ManagePhotos.aspx?id=" + adId.ToString()
                End If
    
            Else
                e.Cancel = True
            End If
        End Sub
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    
            ' Limit Description text.
            DescriptionTextBox.Attributes.Add("onkeydown", "textCounter(this,500);")
            DescriptionTextBox.Attributes.Add("onkeyup", "textCounter(this,500);")
    
            If Not Page.IsPostBack Then
    
                PostAdWizard.MoveTo(PostAdWizard.WizardSteps(0))
    
                Dim qsRelistId As String = Request.QueryString("relist")
                If Not (qsRelistId Is Nothing) Then
                    Dim adId As Integer
                    If Int32.TryParse(qsRelistId, adId) Then
                        LoadPreviousAd(adId)
                    End If
                End If
            End If
        End Sub
    
        Protected Sub LoadPreviousAd(ByVal adId As Integer)
            Dim ad As AdsDataComponent.AdsRow = AdsDB.GetAdById(adId)
            If Not (ad Is Nothing) Then
                If ad.MemberId = Profile.MemberId Then
                    PreviousAdId = adId
    
                    SetCurrentCategory(ad.CategoryId)
    
                    If CType(ad.AdType, AdType) = AdType.Wanted Then
                        AdTypeSelection.SelectedIndex = 1
                    Else
                        AdTypeSelection.SelectedIndex = 0
                    End If
                    TitleTextBox.Text = ad.Title
                    DescriptionTextBox.Text = ad.Description
                    UrlTextBox.Text = ad.URL
                    LocationDropDown.CurrentLocation = ad.Location
                End If
            End If
        End Sub
    
    
        Protected Sub UpdateCategoryDisplay()
            Me.CategoryPathLabel.Text = CategoryPath.FullCategoryPath
        End Sub
    
    
        Protected Sub SubcategoriesDS_Selected(ByVal sender As Object, ByVal e As ObjectDataSourceStatusEventArgs)
            Dim subCategories As List(Of CachedCategory) = CType(e.ReturnValue, List(Of CachedCategory))
            If subCategories Is Nothing OrElse subCategories.Count = 0 Then
                PostAdWizard.MoveTo(PostAdWizard.WizardSteps(1))
            End If
        End Sub
    
    
        Protected Sub SetCurrentCategory(ByVal categoryId As Integer)
            CategoryPath.CurrentCategoryId = categoryId
            UpdateCategoryDisplay()
        End Sub
    
    
        Protected Sub SubcategoriesList_ItemCommand(ByVal [source] As Object, ByVal e As DataListCommandEventArgs)
            Dim categoryId As Integer = Convert.ToInt32(e.CommandArgument)
            SetCurrentCategory(categoryId)
        End Sub
    
    
        Protected Sub CategoryPath_CategorySelectionChanged(ByVal sender As Object, ByVal e As CategorySelectionChangedEventArgs)
            UpdateCategoryDisplay()
        End Sub
    
    
        Protected Sub ChangeCategoryButton_Click(ByVal sender As Object, ByVal e As EventArgs)
            SetCurrentCategory(DefaultValues.CategoryIdMinValue)
            PostAdWizard.MoveTo(PostAdWizard.WizardSteps(0))
        End Sub
    
        Protected Sub PostAdWizard_PreviousButtonClick(ByVal sender As Object, ByVal e As WizardNavigationEventArgs)
            If e.NextStepIndex = 0 Then
                SetCurrentCategory(DefaultValues.CategoryIdMinValue)
            End If
        End Sub
    
        Protected Sub ValidLocationRequired_ServerValidate(ByVal [source] As Object, ByVal args As ServerValidateEventArgs)
            args.IsValid = Not LocationDropDown.CurrentLocation.Equals(String.Empty)
        End Sub
    
        Protected Sub PriceValidator_ServerValidate(ByVal [source] As Object, ByVal args As ServerValidateEventArgs)
            Dim p As Decimal = -1
            If Decimal.TryParse(PriceTextBox.Text, p) Then
                args.IsValid = p >= 0
            Else
                args.IsValid = False
            End If
        End Sub
        Protected Sub URLValidator_ServerValidate(ByVal [source] As Object, ByVal args As ServerValidateEventArgs)
    
            args.IsValid = False
            Dim URLTextBox As TextBox = CType(AdDetailsStep.FindControl("UrlTextBox"), TextBox)
            If Not (URLTextBox Is Nothing) AndAlso Not (URLTextBox.Text.Equals(String.Empty)) Then
                Try
                    Dim uri As New Uri(URLTextBox.Text)
                    If (uri.IsWellFormedOriginalString() And _
                    (uri.Scheme = "http" Or uri.Scheme = "https")) Then
                        args.IsValid = True
                    End If
    
                Catch ex As Exception
    
                End Try
    
            Else
                ' Empty URL is okay.
                args.IsValid = True
            End If
    
        End Sub
    End Class


     

     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 16, 2010 3:37 PM