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

<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. 百度地图JS--2

    转载请注明出处 本文为原创 作者:injuer 严禁用于商业用途,仅学习交流 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transiti ...

  2. 我眼中的PageRank算法详解

    随着互联网的发展,网络上已有的网页数量庞大,并且每天都会有很多网页发布,如何权衡这些重要度的排名是一个很重要的问题.我们今天就来了解一下PageRank算法. 首先我们要来了解一下图的概念,请看图1. ...

  3. 点击button触发onclick事件判空后依旧自动跳转

    这是一个前端的问题. 其中判断字符串为空的脚本代码是这样的: var remark = $("#Remark").val(); //判空.注意:var reg = /空格/g; v ...

  4. Windows Visual Studio 下配置OpenGL

    很多同学不是很清楚OpenGL的配置,一个个帮忙配置也不是办法,干脆就写一篇教程好了. 本人使用的是Visual Studio 2015版本,对于Visual Studio 2012版本的配置会稍有不 ...

  5. Powerdesign使用小技巧(转载)

    1.做CDM模型的时候,因为开始定义ITEM的时候,没有注意把NAME和CODE全定义成一样的.结果后面想改的时候比较麻烦,一修改NAME结果CODE也变了.后来找到两个方法可以解决这个问题.A.Po ...

  6. nginx-1.2.7 + tcp_proxy_module手动编译安装

    Nginx开源软件默认没有提供TCP协议的负载均衡,下面记录一下我的安装过程: 1. 下载nginx最新稳定版的源码.可访问:http://www.nginx.org 或 linux命令下载到本地: ...

  7. 003实现字符串反转reverse

    这个简单就直接代码了 //写代码翻转一个C风格的字符串. (C风格的意思是"abcd"须要用5个字符来表示,包括末尾的 结束字符) #include <stdio.h> ...

  8. Request介绍及演示样例 PART1

    Request在ServletAPI的规范连接地址http://blog.csdn.net/zghwaicsdn/article/details/51035146 HTTP简介 URL是浏览器寻找信息 ...

  9. 终端I/O termios属性设置 tcsetattr设置(转)

    终端I/O有两种不同的工作方式: 规范方式输入处理.在这种方式中,终端输入以行为单位进行处理.对于每个读要求,终端驱动程序最多返回一行. 非规范方式输入处理.输入字符不以行为单位进行装配. 如果不作特 ...

  10. QT界面 理解QStyle和QStyleOption以及QStyleFactory

    QStyleOption类和QStyle类简介 QStyleOption类存储QStyle函数使用的参数.QStyleOption及其子类包含了QStyle函数绘制图形元素所需的所有信息. 由于性能原 ...