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

<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. 【Firefly API文档】—— Package Distributed

    http://bbs.gameres.com/forum.php?mod=viewthread&tid=219654 package distributed 这个包中主要封装了各个服务进程间进 ...

  2. python——修饰符

    修饰符基础--闭包 什么是闭包呢?标准的概念大家可以看wikipedia上的解释 举个例子: def do_add(base): def add(increase): return base + in ...

  3. LoadRunner字符串处理 - 补齐字符串

    有些时候需要在某个字符串的前面用0补齐,以便满足长度的格式要求. 在LoadRunner中可以封装出一个函数来处理这种问题: /* Function to pad a string to x char ...

  4. 学会使用简单的MySQL操作

    第十八章 学会使用简单的MySQL操作 在前面两个章节中已经介绍过MySQL的安装了.可是光会安装还不够.还须要会一些主要的相关操作.当然了,关于MySQL的内容也是非常多的.仅仅只是对于linux系 ...

  5. PHP 导出 CSV 文件用 Excel 打开出现中文乱码

    本篇文章由:http://xinpure.com/php-export-csv-file-opened-by-excel-appear-garbled/ 乱码情况 写了一段导出 CSV 文件的代码,可 ...

  6. mac 安装2个xcode 时会导致找不到xcodebuild

    mac 安装2个xcode 时会导致找不到xcodebuild 解决方案: sudo  xcode-select --switch /Applications/Xcode.app/Contents/D ...

  7. Swashbuckle一个webapi调试利器

    开发weibapi通常会使用postman或者其他模拟http请求的工具去模拟请求.但是这些工具需要自己保存请求地址的url以及参数 每次我都是先查询wiki看参数. 看见同事再用Swashbuckl ...

  8. SQL数据库相关

    数据库相关知识点 SQL, 对表的理解, 对表的主键, 外键的理解, 视图, 为什么要有视图, 视图有什么功能, 视图与表有什么区别 主键是唯一标识的一条记录,不能重复,不能为空. 表的外键是另一个表 ...

  9. 一.软件介绍(apache lighttpd nginx)

    一.软件介绍(apache  lighttpd  nginx) 1. lighttpd Lighttpd是一个具有非常低的内存开销,cpu占用率低,效能好,以及丰富的模块等特点.lighttpd是众多 ...

  10. CentOS6.x修改主机名,关闭防火墙

    一.centos默认主机名为localhost,不方便管理,此次,我修改为noi. 1.修改网络配置文件:/etc/sysconfig/network 首先,备份一下源文件,注意date命令和加号之间 ...