简体   繁体   English

DropDownList 不会在 SelectedIndexChanged 上回发

[英]DropDownList doesn't postback on SelectedIndexChanged

I'm writing an ASP.Net webform with some DropDownList controls on it.我正在编写一个带有一些 DropDownList 控件的 ASP.Net 网络表单。 Then user changes selected item in one of dropdowns, ASP.Net doesn't seem to handle SelectedIndexChanged event until form is submitted with a 'Submit' button click.然后用户更改下拉列表之一中的选定项目,ASP.Net 似乎没有处理 SelectedIndexChanged 事件,直到通过单击“提交”按钮提交表单。 How do I make my dropdowns handle SelectedIndexChanged instantly?如何让我的下拉列表立即处理 SelectedIndexChanged?

PS It's a classic question I have answered too many times, but it seems no one asked it before on stackoverflow. PS 这是一个经典问题,我已经回答了太多次了,但似乎没有人在 stackoverflow 上问过这个问题。

Setting the AutoPostback property to true will cause it to postback when the selection is changed.AutoPostback属性设置为 true 将导致它在选择更改时回发。 Please note that this requires javascript to be enabled.请注意,这需要启用 javascript。

You need to set the AutoPostBack property of the list to true.您需要将列表的AutoPostBack属性设置为 true。

Also, if you're populating the contents of the drop down list from the code behind (getting the contents of the list from a database, for example) - make sure you're not re-binding the data in every postback.此外,如果您要从后面的代码中填充下拉列表的内容(例如,从数据库中获取列表的内容),请确保您没有在每次回发中重新绑定数据。

Sometimes people are caught out by binding the drop-down in the page load event without putting it in an If Not IsPostBack .有时人们会因为在页面加载事件中绑定下拉菜单而不将其放入If Not IsPostBack中而被抓住。 This will cause the event not to fire.这将导致事件不触发。

The same is also true of repeaters and ItemCommand events.中继器和ItemCommand事件也是如此。

if you are populating the dropdown list during page load then each time the page postback it will reload the list thus negating your postback method.如果您在页面加载期间填充下拉列表,那么每次页面回发时它都会重新加载列表,从而否定您的回发方法。 you need to be sure to load the dropdownlist only if (!ispostback)您需要确保仅在 (!ispostback) 时加载下拉列表

Set the AutoPostBack property of DropDownList to true.将 DropDownList 的 AutoPostBack 属性设置为 true。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 DropDownList不调用SelectedIndexChanged? - DropDownList doesn't call SelectedIndexChanged? DropDownList不会在SelectedIndexChanged上回发 - DropDownList does not postback on SelectedIndexChanged Dropdownlist SelectedIndexChanged在每次回发时触发 - Dropdownlist SelectedIndexChanged firing on every postback 如何在不回发的情况下触发dropdownlist的SelectedIndexChanged? - How to fire dropdownlist's SelectedIndexChanged without postback? DropDownList 的 SelectedIndexChanged() 如何在没有 PostBack 的情况下工作? - How DropDownList's SelectedIndexChanged() works without PostBack? 动态加载的下拉列表控件不会触发 SelectedIndexChanged 事件 - Dynamically loaded dropdownlist control doesn't fire SelectedIndexChanged event 动态下拉列表控件不会触发Selectedindexchanged事件 - Dynamic dropdownlist control doesn't fire Selectedindexchanged event dropdownlist中的First Item根本不会触发SelectedIndexChanged - First Item in dropdownlist doesn't fire SelectedIndexChanged at all 在C#中使用Databind,DropDownList不会在SelectedIndexChanged上触发事件 - DropDownList doesn't Fire Event on SelectedIndexChanged Using Databind in C# DropDownList何时保留SelectedIndexChanged事件处理程序的回发值 - When does a DropDownList retain the value from postback at the SelectedIndexChanged Event Handler
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM