我有一个 ASP.NET DropDownList
与 AutoPostBack=true
和 EnableViewState=false
.我在页面上有一个什么都不做的按钮。如果我更改 ddl 中的选择,它会回发,这是预期的。如果我单击按钮,页面会回发,ddl 的 SelectedIndexChanged
火灾。为什么会被解雇?
最佳答案
"Thanks for your feedback. If ViewState is disabled on the page or on the DropDownList control, the selected index cannot be saved, so each postback looks like the selected index has been changed. You can save the selected index yourself and compare against it to see if the selection has really changed, or you can enable ViewState on the DropDownList. "
在您的情况下,下拉列表的 View 状态为 false。启用相同或您可以按照上面的建议比较所选项目的索引。
关于.net - 为什么在单击按钮时为 DropDownList 触发 SelectedIndexChanged?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2452826/