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

我有一个ASP.NET DropDownList,AutopostBack = true,EnableViewState = false.我在页面上有一个什么都不做的按钮.如果我更改ddl中的选择,它会回发,这是预期的.如果我单击该按钮,页面会回发,并且会触发ddl的SelectedindexChanged.为什么会被解雇?

解决方法

来自Microsoft的反馈: – 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. “

在您的情况下,下拉列表的视图状态为false.启用相同或您可以比较上面建议的所选项目的索引.

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...