配置中使用 或在页面中使用 <%@ Page Ena

jy410058188 2010-12-07 08:30:13
回发或回调参数无效。在配置中使用 <pages enableEventValidation="true"/> 或在页面中使用 <%@ Page EnableEventValidation="true" %> 启用了事件验证。出于安全目的,此功能验证回发或回调事件的参数是否来源于最初呈现这些事件的服务器控件。如果数据有效并且是预期的,则使用 ClientScriptManager.RegisterForEventValidation 方法来注册回发或回调数据以进行验证。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.ArgumentException: 回发或回调参数无效。在配置中使用 <pages enableEventValidation="true"/> 或在页面中使用 <%@ Page EnableEventValidation="true" %> 启用了事件验证。出于安全目的,此功能验证回发或回调事件的参数是否来源于最初呈现这些事件的服务器控件。如果数据有效并且是预期的,则使用 ClientScriptManager.RegisterForEventValidation 方法来注册回发或回调数据以进行验证。

源错误:

执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。

堆栈跟踪:


[ArgumentException: 回发或回调参数无效。在配置中使用 <pages enableEventValidation="true"/> 或在页面中使用 <%@ Page EnableEventValidation="true" %> 启用了事件验证。出于安全目的,此功能验证回发或回调事件的参数是否来源于最初呈现这些事件的服务器控件。如果数据有效并且是预期的,则使用 ClientScriptManager.RegisterForEventValidation 方法来注册回发或回调数据以进行验证。]
System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument) +8626793
System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument) +72
System.Web.UI.WebControls.DropDownList.LoadPostData(String postDataKey, NameValueCollection postCollection) +53
System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) +13
System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +346
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1743


...全文
288 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
孟子E章 2010-12-12
  • 打赏
  • 举报
回复
不能验证是你的代码中存在错误。js代码
document.form1.dddlHeadShip.value;
改成
document.form1.ddlHeadShip.value;


简单的测试代码如下
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebForm1.aspx.cs" Inherits="WebForm1"
EnableEventValidation="false" %>

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

<script type="text/javascript">
canSubmit = true;
function chkUserName() {
return true;
}
function chkVal() {
/*
有效性验证$("#txtAge")
*/


document.getElementById("hidHeadShipValue").value = document.form1.ddlHeadShip.value;

var submitOk = true;
submitOk = chkUserName() & canSubmit;
submitOk = chkEmail() & canSubmit;
submitOk = chkAge() & canSubmit;
if (0 == submitOk || false == canSubmit) {
alert("你输入的信息有误,请认真检查");
return false;
} else
return true;
}

function getHeadship() {
//二级连动
var dept_code = document.form1.ddlDepart.value;
var headship_list = document.getElementById("hidHeadship").value;
alert(dept_code);

var headship = headship_list.split(",");
//alert(headship);
document.form1.ddlHeadShip.length = 0;
var i = 0;
while (i < headship.length - 1) {

var headship_2 = headship[i].split("|");
if (dept_code == headship_2[1]) {
var op = new Option(headship_2[2], headship_2[0]);
document.form1.ddlHeadShip.options.add(op);
}
i++;
}
}
//------------------检查邮箱----------------------//
function chkEmail() {
var email = document.getElementById("txtEmail").value; //得到输入的邮箱
var reg = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9})$/; //定义验证邮件的正则表达式
if (!email.match(reg))//验证失败,显示错误信息,返回
{
document.getElementById("EmailError").innerHTML = "<font color=\"red\">邮件地址无效!<font>";
canSubmit = false;
return false;
} else {
document.getElementById("EmailError").innerHTML = "<font color=\"green\">邮件地址可用!<font>";
canSubmit = true; //验证通过
return true;
}
}

//----------检查年龄-------------//
function chkAge() {
var age = document.getElementById("txtAge").value;
if (!(isNumber(age) && (parseInt(age) > 5 && parseInt(age) < 200))) {
document.getElementById("AgeError").innerHTML = "<font color=\"red\">请输入正确的年龄</font>";
canSubmit = false;
return false;
} else {
canSubmit = true;
document.getElementById("AgeError").innerHTML = "";
return true;
}
}


function isNumber(oNum) {
if (!oNum) {
if (!oNum)
return false;
}


var strP = /^\d+(\.\d+)?$/;
if (!strP.test(oNum))
return false;

try {

if (parseFloat(oNum) != oNum)
return false;

} catch (ex) {

return false;

}
return true;
}

window.onload = getHeadship;

</script>

</head>
<body>
<form id="form1" runat="server" onsubmit="return chkVal()">
<div id="div_register" runat="server">
部门:
<asp:DropDownList ID="ddlDepart" runat="server" onchange="getHeadship()">
</asp:DropDownList>
岗位:
<asp:DropDownList ID="ddlHeadShip" runat="server">
</asp:DropDownList>
<asp:HiddenField ID="hidHeadShipValue" runat="server" />
<br />
性别:
<asp:RadioButton ID="rbSex0" runat="server" Text="男" GroupName="1" Checked="True" />
<asp:RadioButton ID="rbSex1" runat="server" Text="女" GroupName="1" />
<br />
年龄:
<asp:TextBox ID="txtAge" runat="server" onblur="chkAge()"></asp:TextBox>
<span id="AgeError"></span>
<br />
姓名:
<asp:TextBox ID="txtUserName" runat="server" onblur="chkUserName() "></asp:TextBox>
<span id="NameError"></span>
<br />
EMail:<asp:TextBox ID="txtEmail" runat="server" onblur="chkEmail()"></asp:TextBox>
<span id="EmailError"></span>
<br />
<asp:Button ID="Button1" runat="server" Text="提交" OnClick="Button1_Click" />
<asp:HiddenField ID="hidHeadship" runat="server" />
</div>
</form>
</body>
</html>


另外,对于服务器控件,最好使用
document.getElementById("<%=服务器控件的ClientID%>")来获得对象的引用

另外,可显示的代码已经足以完成所需要的任务,无需添加隐藏的控件
jy410058188 2010-12-09
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 net_lover 的回复:]
<pages enableEventValidation="false"/>
或者
<%@ Page EnableEventValidation="false" %>
[/Quote]

如果按照孟老师做法 <form id="form1" runat="server" onsubmit="return chkVal()" action="WebForm1.aspx">
就不能进行验证了!!!!
jy410058188 2010-12-07
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 net_lover 的回复:]
<pages enableEventValidation="false"/>
或者
<%@ Page EnableEventValidation="false" %>
[/Quote]

表单上就不能提交到服务器了!这是我页面代码
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"  EnableEventValidation="true"  Inherits="Hc.Web.WebForm1" %>

<!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 src="JScript1.js" type="text/javascript"></script>

<script type="text/javascript">

function chkVal()
{
/*
有效性验证$("#txtAge")
*/


document.getElementById("hidHeadShipValue").value = document.form1.dddlHeadShip.value;

var submitOk = true;
submitOk = chkUserName() & canSubmit;
submitOk = chkEmail() & canSubmit;
submitOk = chkAge() & canSubmit;
if (0 == submitOk || false== canSubmit) {
alert("你输入的信息有误,请认真检查");
return false;
} else
return true;
}
/*
function chkUserName(user_name)
{
//用户名重复检测ajax
//由于代码偏多,故这里的验证放在了JScript1.js文件中了

}
*/
function getHeadship() {
//二级连动
var dept_code = document.form1.ddlDepart.value;
var headship_list = document.getElementById("hidHeadship").value;
alert(dept_code);

var headship = headship_list.split(",");
//alert(headship);
document.form1.ddlHeadShip.length = 0;
var i = 0;
while (i <headship.length - 1) {

var headship_2 = headship[i].split("|");
if (dept_code == headship_2[1]) {
var op = new Option(headship_2[2], headship_2[0]);
document.form1.ddlHeadShip.options.add(op);
}
i++;
}
}
//------------------检查邮箱----------------------//
function chkEmail() {
var email = document.getElementById("txtEmail").value; //得到输入的邮箱
var reg = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9})$/; //定义验证邮件的正则表达式
if (!email.match(reg))//验证失败,显示错误信息,返回
{
document.getElementById("EmailError").innerHTML = "<font color=\"red\">邮件地址无效!<font>";
canSubmit = false;
return false;
}else{
document.getElementById("EmailError").innerHTML = "<font color=\"green\">邮件地址可用!<font>";
canSubmit = true; //验证通过
return true;
}
}

//----------检查年龄-------------//
function chkAge() {
var age = document.getElementById("txtAge").value;
if (!(isNumber(age) && (parseInt(age) > 5 && parseInt(age) < 200))) {
document.getElementById("AgeError").innerHTML = "<font color=\"red\">请输入正确的年龄</font>";
canSubmit = false;
return false;
} else {
canSubmit=true;
document.getElementById("AgeError").innerHTML = "";
return true;
}
}


function isNumber(oNum) {
if (!oNum) {
if (!oNum)
return false;
}


var strP = /^\d+(\.\d+)?$/;
if (!strP.test(oNum))
return false;

try {

if (parseFloat(oNum) != oNum)
return false;

} catch (ex) {

return false;

}
return true;
}

window.onload = getHeadship;

</script>

</head>
<body>
<form id="form1" runat="server" onsubmit="return chkVal()">
<div id="div_register" runat="server">
部门: <asp:DropDownList ID="ddlDepart" runat="server" onchange="getHeadship()">
</asp:DropDownList>
岗位:
<asp:DropDownList ID="ddlHeadShip" runat="server" >
</asp:DropDownList>
<asp:HiddenField ID="hidHeadShipValue" runat="server" />
<br />
性别: <asp:RadioButton ID="rbSex0" runat="server" Text="男" GroupName="1"
Checked="True" />
<asp:RadioButton ID="rbSex1" runat="server" Text="女" GroupName="1" />
<br />
年龄: <asp:TextBox ID="txtAge" runat="server" onblur="chkAge()"></asp:TextBox>
<span id="AgeError" ></span><br />
姓名: <asp:TextBox ID="txtUserName" runat="server" onblur="chkUserName() "></asp:TextBox>
<span id="NameError"></span><br />
EMail:<asp:TextBox ID="txtEmail" runat="server" onblur="chkEmail()"></asp:TextBox>
<span id="EmailError"></span><br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="提交" />
<asp:HiddenField ID="hidHeadship" runat="server" /></div>
</form>
</body>

</html>
孟子E章 2010-12-07
  • 打赏
  • 举报
回复
<pages enableEventValidation="false"/>
或者
<%@ Page EnableEventValidation="false" %>

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧