客户端用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事件中写 ...
随机推荐
- Unity3D性能优化小tips——把this.transform缓存缓存起来
Unity3D开发时中有一个小tips,这在官方的文档里其实有提及的,但不那么显眼,这里小说一下: 在MonoBehaviour进行编程时,我们经常会用this.transform, this.gam ...
- 字符串在内存中的存储——C语言进阶
字符串是以ASCII字符NUL结尾的字符序列. ASCII字符NUL表示为\0.字符串通常存储在数组或者从堆上分配的内存中.只是,并不是全部的字符数组都是字符串,字符数组可能没有NUL字符. 字符数组 ...
- Spring Boot(二)Application events and listeners
一.自定义监听器: 1.创建: META-INF/spring.factories 2.添加: org.springframework.context.ApplicationListener=com. ...
- SSH限制ip登陆
linux限制IP访问ssh 在/etc/hosts.allow输入 (其中192.168.10.88是你要允许登陆ssh的ip,或者是一个网段192.168.10.0/24) sshd: ...
- 编译ORBSLAM2 build_ros.sh,实现kinect2在ROS环境下运行ORBSLAM2
//編譯ORBSLAM2 build_ros.sh參考:“http://www.cnblogs.com/bigzhao/p/6635770.html”1.source ~/.bashrc出現問題:ct ...
- HTML5学习笔记 视频
许多时髦的网站都提供视频.html5提供了展示视频的标准 检测您的浏览器是否支持html5视频 Web上的视频 直到现在,仍然不存在一项旨在网页上显示视频的标准. 今天,大多数视频是通过插件(比如Fl ...
- node.js零基础详细教程(6):mongodb数据库操作 以及导入导出
第六章 建议学习时间4小时 课程共10章 学习方式:详细阅读,并手动实现相关代码 学习目标:此教程将教会大家 安装Node.搭建服务器.express.mysql.mongodb.编写后台业务逻辑. ...
- ASP.NET MVC 简单的分页思想与实现
首先我们通过VS创建一个空的基于Razor视图引擎的ASP.NET MVC3 Web应用程序,命名为JohnConnor.Web 对创建过程或Razor不太了解的看官,请移步 ASP.NET MVC ...
- Shell编程二
告警系统需求分析 1.(虽然之前我们学习了zabbix,但有时候也不能满足我们的需求,比如比较冷门的监控项目需要写自定义脚本,或者服务器网络有问题,没有办法将客户端的数据发送到服务端.) 程序架构: ...
- javascript 反调试 监听用户打开了Chrome devtool
let div = document.createElement('div'); let loop = setInterval(() => { console.log(div); ...