Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi Everyone,

Getting this following error on button click. I have a page with Dropdownlist and a button.
I'm binding the countrylist from DB to dropdownlist using Jquery's ajax method. Now when i click on button to store the selected country in some other table, raising this below error.
I have tried with the enableEventValidation="false", but not getting the selected values from the dropdown.

any idea?

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.

XML
[ArgumentException: Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> 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.]
   System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument) +8644649
   System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument) +69
   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) +343
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1743
Posted
Comments
Kornfeld Eliyahu Peter 24-Jul-13 7:36am    
1. In general when you do not set control ids you may get this error
2. Client side changes may trigger also
3. I may able to help you if you let me see your code...
Rockstar_ 24-Jul-13 7:42am    
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DDLFillWithJSON.aspx.cs" Inherits="JSON_DDLFillWithJSON" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="../Scripts/jquery-2.0.2.js"></script>
<script type="text/javascript">

$(document).ready(function () {
debugger;
getCountryList();
// $('#ddlCountry').html();

});

function getCountryList() {
$.ajax({

url: "DDLFillWithJSON.aspx/GetCountryList",
type: "GET",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: onSuccess,
error: geterror,
failure: function (response) { alert(response.d); },
async: false

});
}


function onSuccess(response) {
debugger;
var myobject = eval(response.d);
BuildList(myobject);
}

function BuildList(msg) {
debugger;
var select = '';
for (var i = 0; i < msg.length; i++) {
select += '<option value=' + msg[i].MId + '>' + msg[i].MasterName + '</option>' + ''
}
var newselect = select;
$('#ddlCountry').html(select);
return false;
}

function geterror(xhr, ajaxOptions, thrownError) {
alert(xhr.status + '</br>' + xhr.responseText + '</br>' + thrownError);
}



</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
<asp:UpdatePanel runat="server" ID="upd" UpdateMode="Always">
<contenttemplate>
<asp:DropDownList runat="server" ID="ddlCountry">






<asp:Button Text="Click Me" runat="server" ID="btnClickMe" OnClick="btnClickMe_Click" />

</div>
</form>
</body>
</html>
Rockstar_ 24-Jul-13 7:42am    
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class JSON_DDLFillWithJSON : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

[System.Web.Services.WebMethod]
[ScriptMethod(UseHttpGet = true)]
public static string GetCountryList()
{
Connection cnn = new Connection();
return cnn.Get_CountryList();

}
protected void btnClickMe_Click(object sender, EventArgs e)
{
var cname= ddlCountry.SelectedItem;
var cMid = ddlCountry.SelectedItem;
}

protected override void Render(HtmlTextWriter writer)
{
ClientScript.RegisterForEventValidation(btnClickMe.UniqueID.ToString());
base.Render(writer);
}
}
ZurdoDev 24-Jul-13 8:08am    
If you have special characters in your data when it posts back .net flags it as being potentially dangerous.
Rockstar_ 24-Jul-13 23:40pm    
No special chars in the data

1 solution

 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900