使用Json将数据绑定到asp dropdownlist时出错 [英] Error while binding data to asp dropdownlist with Json
问题描述
我在与Json一起使用Dropdown绑定时遇到了此错误,在我使用EnableEventValidation ="true"的同时,我还通过scriptmanager stiil检查了如下相同的错误
无效的回发或回调参数.使用in配置或<%@页面EnableEventValidation ="true"%>启用事件验证.在页面中.为了安全起见,此功能验证回发或回调事件的参数源自最初呈现它们的服务器控件.如果数据有效且预期,请使用ClientScriptManager.RegisterForEventValidation方法以注册回发或回调数据以进行验证.
这是我的aspx代码
Hi I am getting this error while using Dropdown binding with Json am using EnableEventValidation="true" and i also check with scriptmanager stiil am getting same error as follows
Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
This is my aspx code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Dropdown with JSON.aspx.cs" Inherits="Dropdown_with_JSON" EnableEventValidation="true" %>
<!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="Scripts/jquery-1.8.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Jquery.asmx/BindDropdown",
data: "{}",
dataType: "json",
success: function (data) {
$("#DropDownList1").append($("<option></option>").val("").html("srre"));
$.each(data.d, function (key, value) {
$("#DropDownList1").append('<option value="' + value.CategoryID+ '">' + value.CategoryName + '</option>');
});
},
error: function (result) {
alert("Error");
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<br />
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="DropDownList1" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
</form>
</body>
</html>
推荐答案
(文档).ready( function (){
(document).ready(function () {
.ajax({ 类型:" , contentType:" , 网址:" , 数据:" , dataType:" , 成功:功能(数据){
.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "Jquery.asmx/BindDropdown", data: "{}", dataType: "json", success: function (data) {
(" #DropDownList1").append(
("#DropDownList1").append(
这篇关于使用Json将数据绑定到asp dropdownlist时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!