无刷新二级联动菜单获取菜单值的问题

 

我在页面上放置两个DropDownList,其ID分别为DropDownList1和DropDownList2 利用javascript 实现了无刷新联动, 用户提交选择后,在codebehind中我利用this.Request["DropDownList2"]可以获取DropDownList2的选择值,这在一个aspx页面中没有任何问题 而当我把此项功能写在一个ascx用户控件中时,问题来了, this.Request["DropDownList2"]的值总是为空连this.Request["DropDownList1"]的值也为空 后来我查看调用该ascx控件的aspx页面的html源文件,发现两个DropDownList的id并不是DropDownList1和DropDownList2了, 于是改用this.Request[this.DropDownList1.ClientID]和this.Request[this.DropDownList2.ClientID]获取用户选择值,依然为空 ================================

解决方式:在两个DropDownList傍边又加了一个HtmlInputHidden,其id为myHidden设置为服务器端运行然后在Page_Load中做如下设置

DropDownList2.Attributes.Add("onBlur", ""+this.myHidden.ClientID+".value=this.options[this.selectedIndex].value");
用this.myHidden.Value便获取到了DropDownList2的用户选择值 然后再用this.DropDownList1.SelectedValue 获取DropDownList1的选择值

 To bmyr:想显示你的“辽宁省”非常简单,直接就是javascript问题,解决方式如下:
把DropDownList2.Attributes.Add("onBlur", ""+this.myHidden.ClientID+".value=this.options[this.selectedIndex].value");
改成
DropDownList2.Attributes.Add("onBlur", ""+this.myHidden.ClientID+".value=this.options[this.selectedIndex].text");
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值