.net - 为什么在单击按钮时为 DropDownList 触发 SelectedIndexChanged?

标签 .net asp.net drop-down-menu viewstate autopostback

我有一个 ASP.NET DropDownListAutoPostBack=trueEnableViewState=false .我在页面上有一个什么都不做的按钮。如果我更改 ddl 中的选择,它会回发,这是预期的。如果我单击按钮,页面会回发,ddl 的 SelectedIndexChanged火灾。为什么会被解雇?

最佳答案

来自微软的反馈:- http://connect.microsoft.com/VisualStudio/feedback/details/103844/dropdownlist-always-fire-selectedindexchanged-event-when-viewstate-is-disabled-and-the-selected-item-is-not-changed-by-the-user

"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/

相关文章:

javascript - 下拉选择不自动填充文本框

c# - 使用 EnableVisualStyles 的 MonthCalendar 控件选择范围?

.net - 强烈命名第 3 方程序集 - 无法加载文件或程序集

c# - 将标量从 SQL Server 返回到 C#

c# - 您最喜欢用什么方法来检查 HTML COLOR 是否有效?

asp.net - LINQ:自定义列名

jquery - 在 Opera 中损坏的下拉菜单

html - 我的 CSS 菜单栏适用于 firefox 但不适用于 chrome

c++ - 为什么我无法通过外围设备进行身份验证?

c# - 在行编辑回发后将 gridview 返回到其原始垂直位置