填充没有任何问题,但是在服务器端却取不出来下拉表中的内容。页面代码如下。

<form id="form1" runat="server"> 
<div> 
<h3>看看用js填充的dropdownlist控件在服务器端能读出来吗?</h3> 
三个级联下拉列表框: 
<asp:DropDownList runat="server" id="bigTypeList" Width="150"> 
</asp:DropDownList> 
<asp:DropDownList runat="server" id="typeList" Width="150"> 
</asp:DropDownList> 
<asp:DropDownList runat="server" id="smalltypeList" Width="150"> 
</asp:DropDownList> 
<br /> 
<asp:Button runat="server" Text="读取下拉表" ID="OK" onclick="OK_Click" /><br /> 
你选的是:<asp:Label runat="server" Text="Label" ID="label1"></asp:Label> 
</div> 
</form>

用来测试的后台代码如下。

protected void OK_Click(object sender, EventArgs e) 

ListItem[] array = new ListItem[3]; 
array[0] = bigTypeList.SelectedItem; //为null 
array[1] = typeList.SelectedItem; //为null 
array[2] = smalltypeList.SelectedItem; //为null 
}

事实证明,在服务器端读取客户端填充的DropDownList控件的值时,根本读不到任何内容。DropDownList.Items.Count为0,DropDownList.SelectedItem为null。 
那么,怎么得到这个值呢,只好使用Request.Form["控件的客户端ID"]了。如下代码所示。

string s=Request.Form[typeList.ClientID];

附:页面中的JavaScript文件。

<script language="javascript" type="text/javascript"> 
$(function () { 
var bigId = '#<%=bigTypeList.ClientID%>'; 
var mediumId = '#<%=typeList.ClientID%>'; 
var smallId = '#<%=smalltypeList.ClientID%>'; 
$(bigId).cascadingDropDown(mediumId, 
'../Services/AutoTypeService.asmx/getAutoType', 
{ valueMember: 'id', displayMember: 'name', cascadingArgName: 'parent' }); 
$(mediumId).cascadingDropDown(smallId, 
'../Services/AutoTypeService.asmx/getSubAutoType', 
{ valueMember: 'id', displayMember: 'name', cascadingArgName: 'parent' }); 
}); 
</script>

客户端用JavaScript填充DropDownList控件 服务器端读不到值的更多相关文章

  1. 客户端用javascript填充Dropdownlist,服务器端获取不到Dropdownlist的值

    今天遇到一个奇怪的问题,某一页面需要使用三级级联下拉列表框.为提高用户体验,采用jQuery的cascadingDropDown插件调用后台Web Services来实现ajax填充. 填充没有任何问 ...

  2. DropDownList 控件不能触发SelectedIndexChanged 事件

    相信DropDownList 控件不能触发SelectedIndexChanged 事件已经不是什么新鲜事情了,原因也无外乎以下几种: 1.DropDownList 控件的属性 AutoPostBac ...

  3. 三级联动---DropDownList控件

    AutoPostBack属性:意思是自动回传,也就是说此控件值更改后是否和服务器进行交互比如Dropdownlist控件,若设置为True,则你更换下拉列表值时会刷新页面(如果是网页的话),设置为fl ...

  4. DropDownList控件

    1.DropDownList控件 <asp:DropDownList runat="server" ID="DropDownList1" AutoPost ...

  5. c#中DropDownList控件绑定枚举数据

    c# asp.net 中DropDownList控件绑定枚举数据 1.枚举(enum)代码: private enum heros { 德玛 = , 皇子 = , 大头 = , 剑圣 = , } 如果 ...

  6. DropDownList 控件

    今天打算学习下dropdownlist控件的取值,当你通过数据库控件或dataset绑定值后,但又希望显示指定的值,这可不是简单的值绑定就OK,上网搜了一些资料,想彻底了解哈,后面发现其中有这么大的奥 ...

  7. DropDownList控件学习

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  8. DropDownList 控件的SelectedIndexChanged事件触发不了

    先看看网友的问题: 根据Asp.NET的机制,在html markup有写DropDownList控件与动态加载的控件有点不一样.如果把DropDownList控件写在html markup,即.as ...

  9. 在FooterTemplate内显示DropDownList控件

    如果想在Gridview控件FooterTemplate内显示DropDownList控件供用户添加数据时所应用.有两种方法可以实现,一种是在GridView控件的OnRowDataBound事件中写 ...

随机推荐

  1. eclipse 模版的使用

    输入:s,然后利用快捷提示键(alt+/)高速的打出:System.out.println(""); 这样能够节省不少时间,使用了三个按键,却打出了这么多的字.事实上,这个功能是利 ...

  2. Android 开发之使用Eclipse Debug调试详解(转)

    转自 http://blog.csdn.net/xys289187120/article/details/6636331 1.在程序中添加一个断点 如果所示:在Eclipse中添加了一个程序断点 在E ...

  3. python基础教程_学习笔记12:充电时刻——模块

    充电时刻--模块 python的标准安装包含一组模块,称为标准库. 模块 >>> import math >>> math.sin(0) 0.0 模块是程序 不论什 ...

  4. centos7 install flash player

    1.在 https://get.adobe.com/cn/flashplayer/ 上选择需要下载版本---> ( YUM,适用于Linux (YUM) ); 2.进入root权限后,进入你的下 ...

  5. Lr_debug_message,Lr_output_message,Lr_error_message,Lrd_stmt,Lrd_fetch

    今天在群里,问了 Lr_debug_message,Lr_output_message,Lr_error_message,Lrd_stmt,Lrd_fetch.下 面我整理了下Lr_debug_mes ...

  6. C语言-常用函数处理

    1.使用fgets #define SLEN 50 char str[SLEN]; fgets(str, SLEN, stdin); i = ; while (str[i] != '\n' & ...

  7. CentOS安装rz\sz命令

    执行以下命令进行安装: yum install lrzsz 安装完成后即可操作rz和sz命令. rz:本地文件上传. sz:Linux系统文件下载到本地.

  8. NGUI的一个bug记录

    在当前帧内触发按钮事件,然后把click事件的list删去,再添加,这时候会再次触发. 不确定,先记一下

  9. excel批量加前后缀

    =A1 & “xxx" 似乎只能在新的列里面添加然后粘贴回去

  10. Atitit。Js调用后台语言 java c#  php swing android  swt的方法大总结

    Atitit.Js调用后台语言 java c#  php swing android  swt的方法大总结 1. Js调用后台语言有三种方法1 2. Swt  BrowserFunction 绑定方法 ...