客户端javascript修改后获取DropDownList的值 [英] Getting the value of a DropDownList after client side javascript modification
问题描述
我在应用程序中有一个级联的DropDownList.级联下拉列表的内容很小,因此无需使用AJAX/JSON来访问数据库以获取内容,我只是在客户端javascript中这样做(这是数据):
I have a cascading DropDownList in an application. The contents of the cascading drop down list is small enough that there isn't a need to use AJAX/JSON to go to a database to get the content, I am just doing it in client side javascript like this (this is a subset of the data):
var val = typeList.value;
var applyTimeList = document.getElementById('clientid');
for (var q=applyTimeList.options.length; q>=0; q--)
applyTimeList.options[q]=null;
if (val == 'AutoRoute')
{
myEle = document.createElement('option') ;
myEle.value = 'SOP Processed';
myEle.text = 'SOP Processed';
applyTimeList.add(myEle) ;
} else if (val == 'Tier1Retention') {
myEle = document.createElement('option') ;
myEle.value = 'Study Processed';
myEle.text = 'Study Processed';
applyTimeList.add(myEle);
myEle = document.createElement('option') ;
myEle.value = 'Study Restored';
myEle.text = 'Study Restored';
applyTimeList.add(myEle);
myEle = document.createElement('option') ;
myEle.value = 'Study Archived';
myEle.text = 'Study Archived';
applyTimeList.add(myEle) ;
}
当我尝试访问服务器端的DropDownList时,无法获取所选的值,它始终返回0作为索引:
When I attempt to access the DropDownList on the server side I can't get the value selected, it always returns 0 as the index:
int index = RuleApplyTimeDropDownList.SelectedIndex;
修改后如何获得在服务器端选择的值?
How can I get the value selected on the Server side after modification?
推荐答案
可以从DropDownList检索值,因为在客户端添加的值将不在ViewState中.正确的方法是:
The value can be retrieved from the DropDownList, because the values added on the client side will not be in the ViewState. The proper way to do this is :
string selectedVal = Request[RuleApplyTimeDropDownList.UniqueID].
这篇关于客户端javascript修改后获取DropDownList的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!