Solved

gridview paging does not work

Posted on 2011-03-02
5
1,147 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Work with App store 7 52
MediaHelp 4 23
Alert on Server memory 2 22
Help with converting xml file to excel using VB.NET 3 20
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

777 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