I have the following Listview defined
<asp:ListView
ID="reportData"
EnableSortingAndPagingCallback="True"
AllowPaging="True"
AllowSorting="True"
PageSize="20"
OnLayoutCreated="LoadReport"
onsorting="reportData_Cause_Sorting"
OnPagePropertiesChanging="reportData_PagePropertiesChanging"
runat="server">
I also have a DataPager defined
<asp:DataPager ID="reportPager" PagedControlID="reportData" PageSize="20" runat="server" >
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
Then, since i Have enableEventValidation set to true, i also have the item registered
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
Page.ClientScript.RegisterForEventValidation(reportData.UniqueID)
Page.ClientScript.RegisterForEventValidation(reportPager.UniqueID)
MyBase.Render(writer)
End Sub
My Initial page load runs just fine, however when I click on a page navigation I am sent to the codebehind and get through the page_load before I receive the error
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 just don't understand why I am continuing to receive the error after I have registered both items for event validation. I never even make it into the RaiseCallbackEvent!
I am a total newbie to these controls and by no means a .net expert either. Any help or advice would be greatly appreciated!
I found the answer. I was calling my function to load the report data and bind it to the ListView both in OnLoad and Render. When I removed the extra call from OnLoad, I no longer received the message. However, paging is still not working, but the problem has moved to a different spot in the code :)
try this simple example.
url passes the values of the paging
protected void DepartmentsListView_SelectedIndexChanged(object sender, ListViewCommandEventArgs e)
{
MessageLabel.Text = "The key value is " +
CountriesListView.SelectedValue.ToString() + ".";
}
<asp:ListView ID="CountriesListView" DataSourceID="ContactsDataSource" runat="server"
DataKeyNames="FirstName" OnItemCommand="DepartmentsListView_SelectedIndexChanged">
<LayoutTemplate>
<table cellpadding="4" width="500" runat="server" id="tblCountries">
<tr id="Tr1" runat="server">
<th id="Th0" runat="server">
ID
</th>
<th id="Th1" runat="server">
Code
</th>
<th id="Th2" runat="server">
Name
</th>
</tr>
<tr runat="server" id="itemPlaceholder" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<asp:LinkButton runat="server" ID="SelectButton" Text="Select" CommandName="Select" />
</td>
<td>
<asp:Label ID="CountryCodeLabel" runat="server" Text='<%# Eval("EmployeeID")%>' />
</td>
<td>
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("FirstName")%>' />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<asp:DataPager runat="server" ID="DataPager2" PageSize="3" PagedControlID="CountriesListView"
QueryStringField="pageNumber">
<Fields>
<asp:NumericPagerField />
</Fields>
</asp:DataPager>
<asp:SqlDataSource ID="ContactsDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:conecec %>"
SelectCommand="SELECT [EmployeeID], [FirstName], [LastName] FROM Employees">
</asp:SqlDataSource>
I think you don't need to change EventValidation
or use RegisterForEventValidation
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();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.