开发者

asp.net drop down firing wrong event

I'm using VS 2010, .net 4, vb.net. I have an asp.net site and on a page have 2 drop down lists.

  <asp:DropDownList ID="ddlClassIndex" runat="server" AutoPostBack="true" />
    <asp:DropDownList ID="ddlClassQBankList" runat="server" AutoPostBack="true" />

When the page first loads i can click on either of these, select an item and the event fires correctly. When i select either of the drop down boxes as a second operation, the first drop down, ddlClassIndex.SelectedIndexChanged fires. What have i done wrong that this would be happening. I do a page.ispostback=false check when the page loads开发者_如何学C and we are also using master pages.

Any idea?

sure..

 Private Sub LoadClass()
    Dim Os As List(Of Dempsey.OldeTestClassIndex) = Nothing
    Dim Oc As New Dempsey.OldeTestClassIndex_Controller
    Os = Oc._GetClassIndexData(0)

    Dim X = From w In Os
            Where w.Active = 3
            Select w

    Os = X.ToList

    With Me.ddlClassIndex
        .DataSource = Os.OrderBy(Function(o) o.ClassTitle)
        .DataTextField = "ClassTitle"
        .DataValueField = "tblClassIndexID"
        .DataBind()
        .Items.Insert(0, New ListItem("Choose Class Title", "0"))
        .SelectedIndex = 0
    End With


End Sub



Protected Sub ddlClassIndex_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlClassIndex.SelectedIndexChanged
    If Me.ddlClassIndex.SelectedIndex > 0 Then
        If ClassHasCategories(Me.ddlClassIndex) = True Then
            Response.Redirect("AddEditQBank.aspx?ClassIndexID=" & Me.ddlClassIndex.SelectedItem.Value)
        Else
            Me.lblStatus.Text = "No Categories"
            Me.lblStatus.Visible = True
        End If

    End If
End Sub

Private Sub LoadClassQBankList()
    Dim ary As New ArrayList
    ary.Add(1)
    ary.Add(2)
    ary.Add(3)

    Dim Os As List(Of Dempsey.OldeTestClassIndex) = Nothing
    Dim Oc As New Dempsey.OldeTestClassIndex_Controller
    Os = Oc._GetClassIndexData(0)

    Dim X = From w In Os Join l In ary On w.Active Equals l
            Where w.KT = 1 And w.RandomTest = 1
                    Select w

    Os = X.ToList

    With Me.ddlClassQBankList
        .DataSource = Os.OrderBy(Function(o) o.ClassTitle)
        .DataTextField = "ClassTitle"
        .DataValueField = "tblClassIndexID"
        .DataBind()
        .Items.Insert(0, New ListItem("Choose Class Title", "0"))
        .SelectedIndex = 0
    End With

End Sub
Protected Sub ddlClassQBankList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlClassQBankList.SelectedIndexChanged
    If Me.ddlClassQBankList.SelectedIndex > 0 Then
        Response.Redirect("ClassQBankList.aspx" & "?ClassIndexID=" & Me.ddlClassQBankList.SelectedValue)
    End If
End Sub

~~~~~~~~~~ More info I am checking for page postback. When i select from the drop down, it redirects to a different page. When i click the back button and selected another value in the other drop down, both SelectedIndexChanged fire. So i do i need to do something with viewstate? before i redired to the other page?


Super old, but for the poor souls still seeing this lacklustre answer you might find some relief in Rick Strahl's (equally old) post: West Wind: ASP.NET ListBoxes, SelectedValue and ViewState.

Spoiler alert: it's a bit hacky and involves doing some of your own view state management.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜