且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当我在客户端创建选项时,如何在服务器端获取下拉选择值

更新时间:2023-08-17 14:15:16

如果在javascript中添加选项,则无法从下拉列表中获取选定的值。此外,您也丢失了SelectedIndexChanged事件处理程序。如果您需要在客户端填充下拉列表并且仍然能够使用SelectedValue属性和SelectedIndexChanged事件,则需要开发自己的ajax服务器控件。或者您可以使用AjaxControlToolkit库中的ComboBox。

You can't get selected value from dropdown if you adding options in javascript. Also, you lost SelectedIndexChanged event handler as well. If you need to fill dropdown on client and still have ability to use SelectedValue property and SelectedIndexChanged event you need to develop own ajax server control. Or you can use some like ComboBox from AjaxControlToolkit library.

尽管如此,如果您仍然希望在客户端上使用常规的DropDown,那么您可以在服务器上获得选定的值在那里: string dropDistSelectedValue = Request.Form [dropDist.UniqueID];

Despite of all above, if you still want to use regular DropDown filled on client then you can get selected value on server as there: string dropDistSelectedValue = Request.Form[dropDist.UniqueID];