日期:2014-05-16  浏览次数:20588 次

jscript给dropdownlist添加新项报错
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="index" %>

<!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 id="Head1" >
    <title>无标题页</title>

<script language="javascript" type="text/javascript">
    
function getData()
{
   document.getElementById("dpdl").options.add(new Option("1","2"));
}

</script>
</head>
<body>
   <form id="form1" runat="server">
   
   
   <asp:DropDownList ID="dpdl"  AutoPostBack="true"  runat="server">
   </asp:DropDownList>
   
   <input id="Submit1" type="submit" onclick="getData()"/>
   </form>
</body>

</html>

------解决方案--------------------
这个是因为你开启了事件来源验证,通过js添加的option对象没有生成对应的viewstate导致出错,关闭事件来源验证,或者参考ArgumentException: 回发或回调参数无效

建立楼主还是去掉viewstate好些,多使用request对象来获取提交的值,而不是使用id.text