asp.net 下拉触发错误事件
我正在使用 VS 2010、.net 4、vb.net。我有一个 asp.net 网站,页面上有 2 个下拉列表。
<asp:DropDownList ID="ddlClassIndex" runat="server" AutoPostBack="true" />
<asp:DropDownList ID="ddlClassQBankList" runat="server" AutoPostBack="true" />
当页面首次加载时,我可以单击其中任何一个,选择一个项目,事件就会正确触发。当我选择任一下拉框作为第二个操作时,第一个下拉框 ddlClassIndex.SelectedIndexChanged
会触发。我到底做错了什么才会发生这样的事情。我在页面加载时执行 page.ispostback=false
检查,并且我们也使用母版页。
有什么想法吗?
当然..
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
~~~~~~~~~~ 更多信息 我正在检查页面回发。当我从下拉列表中选择时,它会重定向到不同的页面。当我单击后退按钮并在另一个下拉列表中选择另一个值时,两个 SelectedIndexChanged 都会触发。那么我需要对视图状态做一些事情吗?在我重定向到另一个页面之前?
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 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
超级老了,但对于那些仍然看到这个平淡答案的可怜人来说,你可能会在 Rick Strahl 的(同样老)的帖子中找到一些安慰:西风:ASP.NET ListBoxes、SelectedValue 和 ViewState。
剧透警告:这有点 hacky,涉及到进行一些您自己的视图状态管理。
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.