Solved

gridview paging does not work

Posted on 2011-03-02
5
1,134 Views
Last Modified: 2012-05-11
I have two grid viewson my page. I have set AutoPostBack="true" EnableViewState="true" AllowPaging="true" for both of them. They show the page numbers on the bottom of the grid, but when I click on another page number I get this error:
"
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: 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.
"
I added the following text to the @Page :
validateRequest="false" enableEventValidation="false"

Now the error is gone but I still cannot navigate through pages on any of my grids.

Pleas check my code and suggest corrections.

Thanks.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" MasterPageFile="Global.master"
    Inherits="_Default" EnableViewState = "true" validateRequest="false" enableEventValidation="false" %>
.......
........

<div class = "caseHistory"><p>      
<asp:UpdatePanel runat="server" ID="UpdatePanel2" ChildrenAsTriggers="false" UpdateMode="Conditional">
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="_Search" EventName="Click" />
                    <asp:AsyncPostBackTrigger ControlID="_SubmitCategory" EventName="Click" />
                </Triggers>
                <ContentTemplate>                                                           
                        <h1><asp:Label ID="CaseHistoryHeader" runat="server" Text="Case History"></asp:Label></h1>
                        <asp:GridView ID="gvCaseHistory" runat="server" 
                        EmptyDataText="No History" AutoGenerateColumns="true"
                            AutoPostBack="true" EnableViewState="true" 
                            AllowPaging="true" PageSize="5" CssClass="mGrid"
                            PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt"
                            OnPageIndexChanging="gvCaseHistory_PageIndexChanging">
                            <PagerSettings Position="Bottom" Mode="NumericFirstLast" 
                                FirstPageText="First" LastPageText="Last"
                                NextPageText="Next" PreviousPageText="Prev" />
                            <PagerStyle HorizontalAlign="Center" />
                        </asp:GridView>                                         
                </ContentTemplate>
                </asp:UpdatePanel>
                </p></div>  
....................
.........................
<div>
                    <asp:UpdatePanel runat="server" ID="UpdatePanel3" ChildrenAsTriggers="false" UpdateMode="Conditional">
                        <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="TimerCaseQueueRefresh" EventName="Tick" />
                            <asp:AsyncPostBackTrigger ControlID="_SubmitCategory" EventName="Click" />
                            <asp:PostBackTrigger ControlID="TextBoxFilter" />
                        </Triggers>
                        <ContentTemplate>                                

                            <asp:GridView ID="gvCaseQueue" runat="server" 
                                AutoPostBack="true" EnableViewState="true"                                
                                EmptyDataText="No Cases Found" CssClass="mGrid"
                                AlternatingRowStyle-CssClass="alt"
                                AutoGenerateColumns="False" 
                                AllowPaging="true" PageSize="20"
                                PagerStyle-CssClass="pgr"                                
                                PagerSettings-Position="Bottom" PagerStyle-HorizontalAlign="Center" 
                                DataSourceID="SqlDataSourceCaseQueue"
                                OnPageIndexChanging="gvCaseQueue_PageIndexChanging">
                                <PagerSettings Position="Bottom" Mode="NumericFirstLast" FirstPageText="First" LastPageText="Last"
                                    NextPageText="Next" PreviousPageText="Prev" />
                                <PagerStyle HorizontalAlign="Center" />
                                <Columns>
                                    <asp:TemplateField HeaderText="Case Queue">
                                        <ItemStyle HorizontalAlign="Center" />
                                        <ItemTemplate>
                                            <a name='<%# Eval("CaseNo") %>' href='Default.aspx?CaseNo=<%# Eval("CaseNo") %>'>
                                                <%# Eval("CaseNo") %></a>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Case Queue">
                                        <ItemStyle HorizontalAlign="Center" />
                                        <ItemTemplate>
                                            <%# Eval("SpecimenType")%>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                            </asp:GridView>
                            <asp:SqlDataSource ID="SqlDataSourceCaseQueue" runat="server" ConnectionString='<%$ ConnectionStrings:CSICustom %>'
                                SelectCommand="CytoStats.Get_Case_Queue" SelectCommandType="StoredProcedure"
                                FilterExpression="SpecimenType like '{0}%'">
                                <FilterParameters>
                                    <asp:ControlParameter Name="SpecimenType" ControlID="TextBoxFilter" PropertyName="Text"
                                        ConvertEmptyStringToNull="true" />
                                </FilterParameters>
                            </asp:SqlDataSource>                                       
                      </ContentTemplate>
                    </asp:UpdatePanel>
                </div>

Open in new window

0
Comment
Question by:patd1
  • 3
  • 2
5 Comments
 
LVL 10

Expert Comment

by:Jini Jose
ID: 35024086
firstly remove the update panel and then try.
you will get the correct error details.
after rectifying the error add the updatepanel
0
 

Accepted Solution

by:
patd1 earned 0 total points
ID: 35027535
Paging works if I remove the UpdatePanel. But I need it on the gvCaseQueue because it has to refresh itself on a timer.

I tried setting ChildrenAsTriggers="true" for and the paging works now. :)

However, if I remove validateRequest="false" enableEventValidation="false" from @Page tag, it still gives the same error. Any ideas what are the implications of this code?

Thanks.
0
 
LVL 10

Expert Comment

by:Jini Jose
ID: 35028167
if it works fine without updatepanel then it should work with updatepanel.
0
 
LVL 10

Expert Comment

by:Jini Jose
ID: 35028180
also please check where you calling the bind grid function. is it inside the page post back ?

also in the page change event, did you bind it again ?
0
 

Author Closing Comment

by:patd1
ID: 35187357
I tried setting ChildrenAsTriggers="true"
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now