日期:2014-05-18  浏览次数:20555 次

服务器端控件和客户端控件的综合应用
我的页面上有一个服务器端控件dropDownList,一个客户端控件selectedList.

我怎样能在客户端取得服务器端控件dropDownList的值,并传递给另一个页面。


------解决方案--------------------
服务器端控件生成的html代码的id是一样的(除了DataGrid那样的),可以用getElementById试试
------解决方案--------------------
在客户端取得服务器端控件dropDownList的值

这个js不就可以吗?getElementById 对的阿,或者看看Clientid
------解决方案--------------------
document.getElementById(“DropDownList1”);
------解决方案--------------------
var vl=aaa.options[0].value;
alert(vl);
------解决方案--------------------
<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "Default2.aspx.cs " Inherits= "Default2 " %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> 无标题页 </title>
<script language= "javascript ">
function Button1_onclick()
{
var aaa= document.getElementById( 'DropDownList1 ');
alert(aaa);
}

</script>
</head>
<body>
<form id= "form1 " runat= "server ">
<asp:DropDownList ID= "DropDownList1 " runat= "server ">
<asp:ListItem> sdfdsfd </asp:ListItem>
<asp:ListItem> dsfacvxz </asp:ListItem>
<asp:ListItem> dfsacvxv </asp:ListItem>
<asp:ListItem> dfscxvcvx </asp:ListItem>
<asp:ListItem> dfdcvxvczxv </asp:ListItem>
<asp:ListItem> dferervccvvc </asp:ListItem>
</asp:DropDownList>
<input id= "dd " type= "button " onclick= "Button1_onclick(); " />


</form>
</body>
</html>

------解决方案--------------------
document.getElementById(“DropDownList1”);
var vl=aaa.options[0].value;
alert(vl);

------解决方案--------------------
options[aaa.selectedIndex].value;是选中值的value