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();
}
}
}