现在的位置: 首页 > 综合 > 正文

无刷新二级联动菜单的Request问题

2013年02月21日 ⁄ 综合 ⁄ 共 770字 ⁄ 字号 评论关闭

页面上放置两个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的选择值

 

抱歉!评论已关闭.