客户端用JavaScript填充DropDownList控件 服务器端读不到值
填充没有任何问题,但是在服务器端却取不出来下拉表中的内容。页面代码如下。
<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控件 服务器端读不到值的更多相关文章
- 客户端用javascript填充Dropdownlist,服务器端获取不到Dropdownlist的值
今天遇到一个奇怪的问题,某一页面需要使用三级级联下拉列表框.为提高用户体验,采用jQuery的cascadingDropDown插件调用后台Web Services来实现ajax填充. 填充没有任何问 ...
- DropDownList 控件不能触发SelectedIndexChanged 事件
相信DropDownList 控件不能触发SelectedIndexChanged 事件已经不是什么新鲜事情了,原因也无外乎以下几种: 1.DropDownList 控件的属性 AutoPostBac ...
- 三级联动---DropDownList控件
AutoPostBack属性:意思是自动回传,也就是说此控件值更改后是否和服务器进行交互比如Dropdownlist控件,若设置为True,则你更换下拉列表值时会刷新页面(如果是网页的话),设置为fl ...
- DropDownList控件
1.DropDownList控件 <asp:DropDownList runat="server" ID="DropDownList1" AutoPost ...
- c#中DropDownList控件绑定枚举数据
c# asp.net 中DropDownList控件绑定枚举数据 1.枚举(enum)代码: private enum heros { 德玛 = , 皇子 = , 大头 = , 剑圣 = , } 如果 ...
- DropDownList 控件
今天打算学习下dropdownlist控件的取值,当你通过数据库控件或dataset绑定值后,但又希望显示指定的值,这可不是简单的值绑定就OK,上网搜了一些资料,想彻底了解哈,后面发现其中有这么大的奥 ...
- DropDownList控件学习
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- DropDownList 控件的SelectedIndexChanged事件触发不了
先看看网友的问题: 根据Asp.NET的机制,在html markup有写DropDownList控件与动态加载的控件有点不一样.如果把DropDownList控件写在html markup,即.as ...
- 在FooterTemplate内显示DropDownList控件
如果想在Gridview控件FooterTemplate内显示DropDownList控件供用户添加数据时所应用.有两种方法可以实现,一种是在GridView控件的OnRowDataBound事件中写 ...
随机推荐
- angular 禁止事件冒泡 和 默认行为
事件冒泡和事件捕捉一直以来都是被讨论的话题,也许大家平时在工作中没有遇到过需要解决事件冒泡的情况举个例子: <body ng-click="fun1()"> <d ...
- shader学习之路(1)- half lambert
在学习这个shader之前先提个经常使用概念.即光照模型.LightModel(光照模型)即是对于物体怎么对打在其上的光做出视觉反应的数学模型.意即表达物体对光反应产生的视觉效果与入射光.物体表面属性 ...
- STL源码剖析(容器适配器)
在STL中,有一类容器完全以底部容器为基础进行实现,这类容器归类为container adapter. priority_queue priority_queue默认使用vector为基础,加上hea ...
- 我的第一个 RN 项目-趣闻
代码地址如下:http://www.demodashi.com/demo/13486.html 项目预览 IOS: Android: 扫描体验: 或者点我 整体功能跟之前小程序和 Android 项目 ...
- php 获取客户端的浏览器信息
就是访问的时候,通过服务端来判断用户是否为移动端,如果是的话就重定向(移动端的页面).事实上现在都是一套搞定的了. 但是还是记录一下吧.没准以后用的到 http://detectmobilebr ...
- phpexcel对于中文路径和中文名称的问题(有疑问)
phpexcel对于中文的文件名无法读取(我本地环境都是utf-8的编码) 是不是win系统识别都是gbk ?(需要把utf-8的字符串改为gbk) $file = "C:\\Users\\ ...
- LayerMask小结
layerMask参数: Raycast (ray : Ray, out hitInfo : RaycastHit, distance : float = Mathf.Infinity, layerM ...
- [svc]caffe安装笔记-显卡购买
caffe,这是是数据组需要做一些大数据模型的训练(深度学习), 要求 服务器+显卡(运算卡), 刚开始老板让买的牌子是泰坦的(这是2年前的事情了). 后来买不到这个牌子的,(jd,tb)看过丽台的, ...
- iOS多线程与网络开发之NSURLCache
郝萌主倾心贡献,尊重作者的劳动成果.请勿转载. // 2 // ViewController.m 3 // NSURLCacheDemo 4 // 5 // Created by haomengzhu ...
- zepto,kissy前端框架实现跨域
三.jsonp的原理:带有src属性标签的跨域资源获取能力,在jsonp中通常使用<script>标签,因为<script>标签获取的跨域资源可以使用回调函数直接处理 json ...