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

前端之家收集整理的这篇文章主要介绍了.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@H_403_8@ ViewState is disabled on the page or@H_403_8@ on the DropDownList control,the@H_403_8@ selected index cannot be saved,so@H_403_8@ each postback looks like the selected@H_403_8@ index has been changed. You can save@H_403_8@ the selected index yourself and@H_403_8@ compare against it to see if the@H_403_8@ selection has really changed,or you@H_403_8@ can enable ViewState on the@H_403_8@ DropDownList. “

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

猜你在找的asp.Net相关文章