I received an error today in one of my web apps that was pretty tough to figure out so I’m documenting it here. Strangely, it occurs in Firefox and Chrome, but not in any version of Internet Explorer (6 through 9 beta).
Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in apage. For security purposes, this feature verifies that arguments topostback or callback events originate from the server control thatoriginally rendered them. If the data is valid and expected, usetheClientScriptManager.RegisterForEventValidation method in order toregister the postback or callback data for validation.
Description: An unhandled exception occurred during the execution ofthe current web request. Please review the stack trace for moreinformation about the error and where it originated in the code.
Exception Details: System.ArgumentException: Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in apage. For security purposes, this feature verifies that arguments topostback or callback events originate from the server control thatoriginally rendered them. If the data is valid and expected, use theClientScriptManager.RegisterForEventValidation method in order toregister the postback or callback data for validation.
The user action that causes this error is selecting from a databound dropdownlist, which, when selected populates a textbox with some text. In the ordinary course of things, the user will select an item from the dropdown and a blurb of text related to that item will be loaded into the textbox.
(Simple stuff, please forgive the formatting)
<asp:ObjectDataSource ID="odsPracticeDetails" runat="server" SelectMethod="GetListConcatenated" TypeName="EducateAL.DAL.dalPracticeDetail">
<SelectParameters>
<asp:Parameter Name="IndicatorID" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:DropDownList ID="ddlLevel" runat="server" AppendDataBoundItems="True" DataSourceID="odsPracticeDetails" DataTextField="PracticeLevelName" DataValueField="Description"
onselectedindexchanged="ddlLevel_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem>-SELECT-</asp:ListItem>
</asp:DropDownList>
protected void ddlLevel_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList list = (DropDownList)sender;
FormView f = (FormView)list.NamingContainer;
TextBox box = (TextBox)f.FindControl("DescriptionTextBox");
box.Text = list.SelectedValue;
}
The “GetListConcatenated” method calls a stored procedure that returns a list of “descriptions” (practice details) associated with a “level” (1-5). Each description is its own record in the database, but I needed to plop all of the descriptions that are related to the “name” selected in the dropdown into a single textbox as prepopulated text for data entry – so I needed to concatenate them by level. “GetListConcatenated” method that populates the dropdown:
public static List<PracticeDetail> GetListConcatenated(int IndicatorID)
{
DataSet ds;
try
{
ds = DBTask.ExecuteDataset(Conn, "Ref_GetPracticeDetailsByIndicator", IndicatorID);
}
catch (Exception ex)
{
throw ex;
}
List<PracticeDetail> l = new List<PracticeDetail>();
foreach (DataRow r in ds.Tables[0].Rows)
{
PracticeDetail p = Fill(r);
l.Add(p);
}
List<PracticeDetail> ConcatList = new List<PracticeDetail>(); //list of practice details concatenated by level
List<PracticeDetail> tmpList; //list of practice details by level
for (int i = 1; i <= 5; i++)
{
tmpList = l.FindAll(p => p.PracticeLevelID.Equals(i));
if (tmpList.Count != 0)
{
PracticeDetail newp = new PracticeDetail();
newp.PracticeLevelName = tmpList[0].PracticeLevelName;
foreach (PracticeDetail item in tmpList)
{
newp.Description = newp.Description + item.Description + "\n\n";
}
ConcatList.Add(newp);
}
}
return ConcatList;
}
Now, guessing that my error might be related to bad data, or potential script injection, I looked through my tables for suspect text, but came up empty. That’s when I noticed the newline characters in the above method.
newp.Description = newp.Description + item.Description + "\n\n";
I put these there to create some spacing between description paragraphs, otherwise the concatenation creates one big paragraph. Just on a hunch, I took them out – ta da! Problem fixed. I won’t begin to say I understand why IE doesn’t have a problem with them, but Firefox and Chrome get validation errors.
Maybe someone who comes across this can let me know.