dropdown databinding event fires twice

Hi,
In my form i have three dropdowns CatalogueId, MainGroupId and SubGroupId, each is the child of previous one.
When i make a response.redirect on my page ,
CatalogueId databinding fires once
MainGroupId databinding fires twice
SubGroupIddatabinding fires twice,

Is this behaviour normal , or is there anything wrong ?
I am asking because i'm popluating meta tags on  SubGroupId_databinding event and since it fires twice, the same meta is generated twice.
Thanks
JoeBlack1980Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

guru_samiCommented:
can we see your code for ddl markup and the databinding...?
0
JoeBlack1980Author Commented:
Dear  Guru_sami, i 'm sending the code , it's a bit long , i hope it wont be a problem.
The actual working page is www.turkeyautospareparts.com/catalogue.aspx
Thanks in advance for the support
 

Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.UI.HtmlControls



Partial Class Catalogue
    Inherits BasePage
    Private AllOemRef As TgcDbDAL.OemRefForTgcRefIdDataTable = Nothing


    Protected Function GetOemForTgcRef(ByVal TgcRefId As Integer) As TgcDbDAL.OemRefForTgcRefIdDataTable
        ' First, see if we've yet to have accessed all of the product information
        If AllOemRef Is Nothing Then
            Dim productAPI As OemRefForTgcRefBLL = New OemRefForTgcRefBLL()
            AllOemRef = productAPI.GetDataOemRefForTgcRefId()
        End If

        ' Return the filtered view
        AllOemRef.DefaultView.RowFilter = "TgcRefId = " & TgcRefId
        Return AllOemRef


    End Function
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim liToBeAssigned As HtmlGenericControl = DirectCast(Me.Master.FindControl("liCatalogue"), HtmlGenericControl)
        liToBeAssigned.Attributes.Add("class", "active")

        TgcReferences.DataSource = TgcRefsDefaultPagingDataSource
    End Sub

    Protected Sub TgcRefsDefaultPagingDataSource_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs) Handles TgcRefsDefaultPagingDataSource.Selected


        ' Reference the PagedDataSource bound to the DataList
        Dim pagedData As PagedDataSource = CType(e.ReturnValue, PagedDataSource)


        ' Remember the total number of records being paged through across postbacks

        TgcRefsDefaultPagingDataSource.DataBind()


        TotalRowCount = pagedData.DataSourceCount


    End Sub






#Region "Page-Level, Paging-Related properties"
    Private Property TotalRowCount() As Integer
        Get
            Dim o As Object = ViewState("TotalRowCount")
            If (o Is Nothing) Then
                Return -1
            Else
                Return Convert.ToInt32(o)
            End If
        End Get
        Set(ByVal Value As Integer)
            ViewState("TotalRowCount") = Value
        End Set
    End Property

    Private ReadOnly Property PageCount() As Integer
        Get
            If TotalRowCount <= 0 OrElse PageSize <= 0 Then
                Return 1
            Else
                Return (Math.Ceiling((TotalRowCount / PageSize)))


                'Return (Math.Round((TotalRowCount / PageSize)))
            End If
        End Get
    End Property


    Private ReadOnly Property PageSize() As Integer

        Get

            Return 21
        End Get
    End Property
#End Region

    Protected Sub TgcRefsDefaultPagingDataSource_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceSelectingEventArgs) Handles TgcRefsDefaultPagingDataSource.Selecting

        e.InputParameters("CatalogueID") = Request.QueryString("SubGroup")

        If Request.QueryString("PageNo") = "" Then
            e.InputParameters("PageIndex") = 0
        Else
            e.InputParameters("PageIndex") = Convert.ToInt32(Request.QueryString("PageNo")) - 1
        End If


        e.InputParameters("PageSize") = 21

    End Sub

    Protected Sub CatalogueId_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CatalogueId.SelectedIndexChanged
        Response.Redirect(String.Format("Catalogue.aspx?Catalogue={0}", CatalogueId.SelectedValue.ToString))
        TgcReferences.DataSource = TgcRefsDefaultPagingDataSource
        TgcReferences.DataBind()


    End Sub
    Protected Sub CatalogueId_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles CatalogueId.DataBound

        If Request.QueryString("Catalogue") = "" Then
            CatalogueId.SelectedIndex = 1
        Else
            CatalogueId.SelectedValue = Request.QueryString("Catalogue")
            End If


    End Sub

    Protected Sub MainGroupId_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MainGroupId.SelectedIndexChanged

        Response.Redirect(String.Format("Catalogue.aspx?Catalogue={0}&Group={1}", CatalogueId.SelectedValue.ToString, MainGroupId.SelectedValue.ToString))
    End Sub
    Protected Sub MainGroupId_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles MainGroupId.DataBound

        If Request.QueryString("Group") = "" Then
            MainGroupId.SelectedIndex = 0
            If Request.QueryString("Catalogue") = "" Then 'Katalogue Seçili degil kataloglari listeleyeim
                DataListCatalogues.DataSource = ObjectDataSource1
                DataListCatalogues.DataBind()
            Else 'Katalogue Seçili ANA BOLUMLERI listeleyeim
                DataListMainGroups.DataSource = ObjectDataSource2
                DataListMainGroups.DataBind()
            End If

        Else
            MainGroupId.SelectedValue = Request.QueryString("Group")
            If Request.QueryString("SubGroup") = "" Then
                DataList1.DataSource = ObjectDataSource3
                DataList1.DataBind()
            Else

            End If

            If CatalogueId.SelectedValue.ToString = "0" Or MainGroupId.SelectedValue.ToString = "0" Or SubGroupId.SelectedValue.ToString = "0" Then
            Else
                TgcReferences.DataBind()
            End If

        End If

    End Sub

    Protected Sub SubGroupId_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles SubGroupId.SelectedIndexChanged
        Response.Redirect(String.Format("Catalogue.aspx?Catalogue={0}&Group={1}&SubGroup={2}&PageNo={3}", CatalogueId.SelectedValue.ToString, MainGroupId.SelectedValue.ToString, SubGroupId.SelectedValue.ToString, 1))

    End Sub
    Protected Sub SubGroupId_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles SubGroupId.DataBound

        If Request.QueryString("SubGroup") = "" Then
            SubGroupId.SelectedIndex = 0

            If Request.QueryString("Group") = "" And Request.QueryString("SubGroup") = "" And Request.QueryString("Catalogue") = "" Then
                Me.Page.Title = "Taksim Group - Catalogue"
            Else
                If Request.QueryString("Group") = "" And Request.QueryString("SubGroup") = "" Then
                    Me.Page.Title = "Taksim Group - " & StrConv(CatalogueId.SelectedItem.ToString, VbStrConv.ProperCase)
                Else
                    If Request.QueryString("SubGroup") = "" Then
                        Me.Page.Title = "Taksim Group - " & StrConv(MainGroupId.SelectedItem.ToString, VbStrConv.ProperCase)
                    End If

                End If
            End If


        Else
            SubGroupId.SelectedValue = Request.QueryString("SubGroup")
            Repeater1.DataSource = CreateData()
            Repeater1.DataBind()
            Repeater2.DataSource = CreateData()
            Repeater2.DataBind()
            Me.Page.Title = "Taksim Group - " & StrConv(MainGroupId.SelectedItem.ToString, VbStrConv.ProperCase) & " - " & StrConv(SubGroupId.SelectedItem.ToString, VbStrConv.ProperCase)

            Dim PageCountAdapter As New TgcDbDALTableAdapters.TgcRefTableAdapter()
            If PageCountAdapter.GetDataTgcRefDetailsFilterByCatCarGPartG(Request.QueryString("SubGroup")).Count > 0 Then


                Label1.Text = MainGroupId.SelectedItem.ToString & " > "
                Label2.Text = SubGroupId.SelectedItem.ToString & " (Total " & TotalRowCount.ToString & " products)"
                Label3.Text = " > Page " & IIf((Request.QueryString("PageNo")).ToString = "", 1, (Request.QueryString("PageNo")).ToString) & " of " & PageCount.ToString

                Label5.Text = MainGroupId.SelectedItem.ToString & " > "
                Label6.Text = SubGroupId.SelectedItem.ToString & " (Total " & TotalRowCount.ToString & " products)"
                Label7.Text = " > Page " & IIf((Request.QueryString("PageNo")).ToString = "", 1, (Request.QueryString("PageNo")).ToString) & " of " & PageCount.ToString

                Dim metatag As New HtmlMeta
                metatag.Name = "Keywords"
                metatag.Content = StrConv(CatalogueId.SelectedItem.ToString, VbStrConv.ProperCase) & "," & StrConv(MainGroupId.SelectedItem.ToString, VbStrConv.ProperCase) & "," & StrConv(SubGroupId.SelectedItem.ToString, VbStrConv.ProperCase)
                Page.Header.Controls.Add(metatag)






            Else
                Label1.Text = "No products in this category"
            End If

        End If


    End Sub

    Function CreateData() As DataTable


        Dim SubGroupIdNo As Int32
        SubGroupIdNo = Convert.ToInt32(IIf(SubGroupId.SelectedValue = "", 0, SubGroupId.SelectedValue))

        Dim PageCountAdapter As New TgcDbDALTableAdapters.TgcRefTableAdapter()
        Dim NumberOfItems As Int32
        NumberOfItems = PageCountAdapter.GetDataTgcRefDetailsFilterByCatCarGPartG(SubGroupIdNo).Count
        Dim NumberOfPages As Int32
        NumberOfPages = Math.Ceiling(NumberOfItems / 21)

        If NumberOfPages <= 1 Then
        Else

            Dim DT As New DataTable()
            DT.Columns.Add(New DataColumn("Group", System.Type.GetType("System.String")))
            DT.Columns.Add(New DataColumn("SubGroupId", System.Type.GetType("System.String")))
            DT.Columns.Add(New DataColumn("CatalogueId", System.Type.GetType("System.String")))
            DT.Columns.Add(New DataColumn("PageNo", System.Type.GetType("System.String")))
            DT.Columns.Add(New DataColumn("EnabledOrNot", System.Type.GetType("System.String")))
            DT.Columns.Add(New DataColumn("CssClass", System.Type.GetType("System.String")))
            Dim NewRow As DataRow

            For indexA = 1 To NumberOfPages
                NewRow = DT.NewRow()
                NewRow("PageNo") = indexA
                NewRow("SubGroupId") = SubGroupIdNo
                NewRow("CatalogueId") = CatalogueId.SelectedValue
                NewRow("Group") = MainGroupId.SelectedValue
                If Request.QueryString("PageNo") = "" Then
                    If indexA = 1 Then
                        NewRow("EnabledOrNot") = "false"
                        NewRow("CssClass") = "TuruncuFonBeyazText"
                    Else
                        NewRow("EnabledOrNot") = "True"
                        NewRow("CssClass") = "AbcDef"
                    End If

                Else
                    If Request.QueryString("PageNo") = indexA Then
                        NewRow("EnabledOrNot") = "False"
                        NewRow("CssClass") = "TuruncuFonBeyazText"
                    Else
                        NewRow("EnabledOrNot") = "True"
                        NewRow("CssClass") = "AbcDef"
                    End If

                End If

                    DT.Rows.Add(NewRow)

            Next

            Return DT
        End If




    End Function

End Class

Open in new window

0
Kaushal AroraTechnical AnalystCommented:
Hi Joe,

This is because you have used the SelectedIndexChanged Event of the dropdown.
When you bind you catalogue dropdown it fires its selectedindexchanged event which binds your MainGroup Dropdown with empty data i suppose and
when you Bind your MainGroup Dropdown it fires the Databind of the SubGroup Dropdown's Databind with Empty Data.

So you need to check It while databinding your Catalogue Dropdown and MainGroupo Dropdown that if they are getting filled in the first run or their actual selectedindex has been changed.

Hope It Helps.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JoeBlack1980Author Commented:
Dear Arora,
Thanks for your reply, which gave me the light,
Altough not the exact reply, that showed me where to look ,
IVe finally removed the datasourceid = xxxxxxxxx for each dropdown on my asp page and,
i implemeted the attached code on pageload event which solved the issue, it was as a matter of fact an unhandled  postpack event.
The page was firing one for redirect and once for postback.
 
So for anyone who will be checking here i 'm giving links to some pages ,
first one is quite specific
http://realfantasy.wordpress.com/2007/10/19/dynamically-controls-creation-aspnet-event-fire-twice-event-bubbling/
http://forums.asp.net/p/1087449/1622087.aspx
http://www.velocityreviews.com/forums/t380042-dropdownlist-databinding-firing-twice-please-help.html 

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not Page.IsPostBack Then
            CatalogueId.DataSource = ObjectDataSource1
            MainGroupId.DataSource = ObjectDataSource2
            SubGroupId.DataSource = ObjectDataSource3
            CatalogueId.DataBind()
            MainGroupId.DataBind()
            SubGroupId.DataBind()

        End If

        TgcReferences.DataSource = TgcRefsDefaultPagingDataSource
    End Sub

Open in new window

0
JoeBlack1980Author Commented:
Thanks for showing me the way
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.