?
Solved

gridview paging does not work

Posted on 2011-03-02
5
Medium Priority
?
1,177 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

770 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