Hello All. Just need an extra set of eyes please. I have simple 3 cascading dropdowns for State, County, City. Please take a look and let me know if you see where this error is coming from because I have been looking for about an hour now.
ERROR>.
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.
Code>>>> State and County work. When you select County and it posts back , is where you get the error..
DropDownList_State.AppendDataBoundItems = true;
DropDownList_State.Items.Add(new ListItem("Select State...", ""));
KoalafiedsDbContext db = new KoalafiedsDbContext();
var query = from t in db.States
orderby t.StateName
select t;
var states = query.ToList<State>();
DropDownList_State.DataSource = states;
DropDownList_State.DataTextField = "StateName";
DropDownList_State.DataValueField = "StateName";
DropDownList_State.DataBind();
}
DropDownList_County.AppendDataBoundItems = true;
KoalafiedsDbContext db = new KoalafiedsDbContext();
var query = from c in db.Counties
where c.StateName == DropDownList_State.SelectedValue
orderby c.CountyName
select c;
var counties = query.ToList<County>();
DropDownList_County.DataSource = counties;
DropDownList_County.DataTextField = "CountyName";
DropDownList_County.DataValueField = "CountyName";
DropDownList_County.DataBind();
}
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
32 Points
145 Posts
Simple Linq statement not working Error.
Jan 10, 2017 08:08 PM|scstevelong|LINK
Hello All. Just need an extra set of eyes please. I have simple 3 cascading dropdowns for State, County, City. Please take a look and let me know if you see where this error is coming from because I have been looking for about an hour now.
ERROR>.
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.
Code>>>> State and County work. When you select County and it posts back , is where you get the error..
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList_County.Enabled = false;
DropDownList_City.Enabled = false;
DropDownList_State.AppendDataBoundItems = true;
DropDownList_State.Items.Add(new ListItem("Select State...", ""));
KoalafiedsDbContext db = new KoalafiedsDbContext();
var query = from t in db.States
orderby t.StateName
select t;
var states = query.ToList<State>();
DropDownList_State.DataSource = states;
DropDownList_State.DataTextField = "StateName";
DropDownList_State.DataValueField = "StateName";
DropDownList_State.DataBind();
}
}
protected void DropDownList_State_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList_County.Enabled = true;
DropDownList_County.Items.Clear();
DropDownList_County.Items.Add(new ListItem("Select County...", ""));
DropDownList_County.AppendDataBoundItems = true;
KoalafiedsDbContext db = new KoalafiedsDbContext();
var query = from c in db.Counties
where c.StateName == DropDownList_State.SelectedValue
orderby c.CountyName
select c;
var counties = query.ToList<County>();
DropDownList_County.DataSource = counties;
DropDownList_County.DataTextField = "CountyName";
DropDownList_County.DataValueField = "CountyName";
DropDownList_County.DataBind();
}
protected void DropDownList_County_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList_City.Enabled = true;
DropDownList_City.Items.Clear();
DropDownList_City.Items.Add(new ListItem("Select City...", ""));
DropDownList_City.AppendDataBoundItems = true;
KoalafiedsDbContext db2 = new KoalafiedsDbContext();
var query = from d in db2.Cities
where d.CountyName == DropDownList_County.SelectedValue
orderby d.CityName
select d;
var cities = query.ToList<City>();
DropDownList_City.DataSource = cities;
DropDownList_City.DataTextField = "CityName";
DropDownList_City.DataValueField = "CityName";
DropDownList_City.DataBind();
}
}
}
Contributor
6410 Points
2527 Posts
Re: Simple Linq statement not working Error.
Jan 11, 2017 05:39 AM|Jean Sun|LINK
Hi scstevelong,
You can try the following solutions to solve your issue.
1. Disable eventvalidation (you lose a little of security).
2. Use ASP.NET Ajax UpdatePanel. The following link shows how to build cascade dropdownlist with updatepanel, please take it as reference.
http://www.aspsnippets.com/Articles/Implement-AJAX-CascadingDropdown-without-Web-Service-in-ASPNet.aspx
About why you get such error, you can refer here : https://blogs.msdn.microsoft.com/amitsh/2007/07/31/why-do-i-get-invalid-postback-or-callback-argument-errors/
Best Regards,
Jean
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.