Invalid post back when button type is Button in datapager
I'm having a listview and datapager inside an update panel. The button type is set as button. Now the problem is that when I click the Next / Previous buttons I get the following error.
Microsoft JScript runtime error: Sys.WebForms.PageRequestMan开发者_StackOverflowagerServerErrorException: 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.
I did some googling and found that I need to set EventValidation as false. But when I do this I get a blank page.
Kindly let me know what needs to be done.
Thanks in advance.
Put this code in Page_Load
event
if (!IsPostBack)
{
BindData();
}
And do not forget modify the PagePropertiesChanged
Event of ListViews
:
protected void lstProducts_PagePropertiesChanged(object sender, EventArgs e)
{
BindData();
}
'EnableEventValidation=true' is ASP.NET protection from tampering of POST-requests (POST injection attack). In your case this error point to dynamic changing page markup on clientside by yourself.
You can resolve problem via disabling this option - <%@Page EnableEventValidation="false" %>, or registering your event by RegisterForEventValidation.
精彩评论