日期:2014-05-19  浏览次数:20318 次

<select /> 与runat=server的冲突
<select   id= "Select2 "   name= "Select2 "   onchange= "showCity(Select2,this.selectedIndex,City_Name2); "     runat=server>
如何解决这样的冲突.   我想在后台取它的值,又想用它的ONCHANGE事件.

------解决方案--------------------
从后台加属性.
------解决方案--------------------
this.Select2.Attributes.Add( "onchange ", "showCity(this,this.selectedIndex,document.all.City_Name2) ");
------解决方案--------------------
这不会冲突啊,前台onchange= " " 后台selectedIndex.value
------解决方案--------------------
不会冲突的.
------解决方案--------------------
2楼的不可以吗
------解决方案--------------------
aspx中:
<select id= "Select2 " name= "Select2 " runat=server>

aspx.cs中:
直接放在page_load函数中
Select2.Attributes.Add( "onchange ", "showCity(this,this.selectedIndex,document.all.City_Name2) ");


------解决方案--------------------
LZ正解
UP
------解决方案--------------------
写在content page里面的控件ID都会被修改,为了有唯一的ID
所以JavaScript操作时最好这样取: document.getElementById( " <%= Control1.ClientID %> ");
------解决方案--------------------
dropdownlist 替换
------解决方案--------------------
document.getElementById( "select1 ").selectedValue