This is a migrated thread and some comments may be shown as answers.

Sys.WebForms.PageRequestManagerParserErrorException / RadAjaxManager & RadGrid

2 Answers 205 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Milan
Top achievements
Rank 1
Milan asked on 03 Oct 2013, 02:30 PM
Hello!

We are have a small problem with our site. Leaving certain pages idle for longer time and then clicking certain controls,
gives a user the following error:

Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.

Details: Error parsing near '�'.

On the server side, the error is as follows:

System.Web.UI.ViewStateException: Invalid viewstate. 
Client IP: 192.168.225.147
Port: 50670
Referer: http://10.176.81.70/List.aspx
Path: /List.aspx
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0


I noticed that the error happens after the time that is set under Idle time-out (minutes) under application pool advanced settings.
As far as potential reasons (Response.Write(), response filters, HttpModules, or server trace is enabled), I can say that they are not the problem.

The fact is also that Windows Authentication is used so user "is" logged in as long as the browser is opened.
In Forms Authentication the problem does not occur since user is logged out after certain amount of time...

I'm attaching the code. Can you, please, tell me, what could be the problem.


<%@ Page Language="C#" MasterPageFile="~/StorePortal.Master" AutoEventWireup="true" CodeFile="List.aspx.cs" Inherits="StorePortal.List"
    Title="<%$ Resources:GRes, Companies %>" %>
<%@ Register Src="~/Controls/SearchBox.ascx" TagName="SearchBox" TagPrefix="MakeIT" %>
<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="Server">
    <meta content="Desc!" name="description" />
    <meta content="Keywords" name="keywords" />
    <link id="RadGridCSS" rel="stylesheet" type="text/css" href="<%= SkinFolder %>/styles/RadControls/Grid.MakeIT.css" />
</asp:Content>
<asp:Content ID="pageAdd" ContentPlaceHolderID="pageAdd" runat="server">
    <asp:ScriptManagerProxy ID="ScriptManagerProxy" runat="server" />
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="Companies">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="Companies" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <MakeIT:SearchBox ID="searchBox" runat="server" SearchGridId="Companies"/>
    <div id="content" class="home">
        <div class="wrap">
            <telerik:RadGrid ID="Companies" runat="server" AllowSorting="true" AutoGenerateColumns="false" OnNeedDataSource="Companies_NeedDataSource" Skin="MakeIT"
                EnableEmbeddedSkins="false" ImagesPath="<%# this.ImagesPath %>" OnItemCommand="Companies_ItemCommand" OnItemDataBound="Companies_ItemDataBound">
                <MasterTableView DataKeyNames="CompanyHash" CommandItemDisplay="Top" Dir="<%$ Resources:GRes, _DisplayDirection %>">
                    <HeaderStyle Height="40" />
                    <CommandItemTemplate>
 
                        <table class="rgCommandTable">
                            <tr>
                                <td>
                                    <asp:Label ID="Companies" runat="server" Text="<%$ Resources:GRes, Companies %>" CssClass="caption" />
                                </td>
                                <td>
                                    <div class="float_right">
                                        <MakeIT:FancyButton ID="AddButton" runat="server" Type="Add" CommandName="InitInsert" CausesValidation="false" Visible="<%# this.UserCanAddCompany %>" />
                                    </div>
                                </td>
                            </tr>
                        </table>
 
                    </CommandItemTemplate>
                    <Columns>
                        <telerik:GridHyperLinkColumn UniqueName="CompanyName" HeaderText="<%$ Resources:GRes, Name %>" DataNavigateUrlFields="CompanyHash" DataNavigateUrlFormatString="Overview.aspx?CompanyID={0}"
                            DataTextField="Name" DataTextFormatString="{0}" />
                        <telerik:GridBoundColumn DataField="Address" HeaderText="<%$ Resources:GRes, Address %>" />
                        <telerik:GridBoundColumn DataField="Telephone" HeaderText="<%$ Resources:GRes, Telephone %>" />
                        <telerik:GridDateTimeColumn DataField="dateProvisioned" HeaderText="<%$ Resources:GRes, DateProvisioned %>" />
                        <telerik:GridEditCommandColumn UniqueName="EditColumn" ButtonType="ImageButton" HeaderStyle-Width="43px" />
                        <telerik:GridButtonColumn CommandName="Delete" ButtonType="ImageButton" HeaderStyle-Width="43px" UniqueName="DeleteColumn" ConfirmTextFormatString="<%$ Resources:GRes, QuestionDeleteCompany %>"
                            ConfirmTextFields="Name" />
                    </Columns>
                    <NoRecordsTemplate>
                        <asp:Literal ID="NoRecords" runat="server" Text="<%$ Resources:GRes, NoRecords %>" />
                    </NoRecordsTemplate>
                </MasterTableView>
            </telerik:RadGrid>
 
            <br />
            <telerik:RadGrid ID="PendingCompanies" runat="server" AllowSorting="true" AutoGenerateColumns="false" OnNeedDataSource="PendingCompanies_NeedDataSource" Skin="MakeIT"
                EnableEmbeddedSkins="false" ImagesPath="<%# this.ImagesPath %>">
                <MasterTableView DataKeyNames="importId" CommandItemDisplay="Top" Dir="<%$ Resources:GRes, _DisplayDirection %>">
                    <HeaderStyle Height="40" />
                    <CommandItemTemplate>
 
                        <table class="rgCommandTable">
                            <tr>
                                <td>
                                    <asp:Label ID="Companies" runat="server" Text="Pending VAR Companies" CssClass="caption" />
                                </td>
                            </tr>
                        </table>
 
                    </CommandItemTemplate>
                    <Columns>
                        <telerik:GridHyperLinkColumn UniqueName="CompanyName" HeaderText="<%$ Resources:GRes, Name %>" DataNavigateUrlFields="ImportId" DataNavigateUrlFormatString="NewCompany.aspx?importId={0}&CompanyID=new"
                            DataTextField="CompanyName" DataTextFormatString="{0}" />
                        <telerik:GridTemplateColumn UniqueName="Address" HeaderText="<%$ Resources:GRes, Address %>">
                            <ItemTemplate>
                                <%# Eval("Address1") %>, <%# Eval("Address2") %>, <%# Eval("City") %>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridBoundColumn DataField="Email" HeaderText="<%$ Resources:GRes, Email %>" />
                        <telerik:GridBoundColumn DataField="Reseller" HeaderText="Reseller" />
                        <telerik:GridBoundColumn DataField="OrderDate" HeaderText="Order date" />
                    </Columns>
                    <NoRecordsTemplate>
                        <asp:Literal ID="NoRecords" runat="server" Text="<%$ Resources:GRes, NoRecords %>" />
                    </NoRecordsTemplate>
                </MasterTableView>
            </telerik:RadGrid>
        </div>
    </div>
</asp:Content>
<asp:Content ID="addonJS" ContentPlaceHolderID="addonJS" runat="server">
</asp:Content>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using UOCommonLib;
using Telerik.Web.UI;
using Store.Data;
 
namespace CompanyPortal
{
    public partial class List : BasePage
    {
        protected bool UserCanAddCompany { get { return ACL.HasAccessToAny("CompanyAdd"); } }
 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!UOPortalLib.UOPortalUiSettings.showElement("Global/DisplayVARCompanies"))
                PendingCompanies.Visible = false;
        }
 
        protected void Page_LoadComplete(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
                Authorize();
        }
 
        public RadGrid SearchGrid { get { return Companies; } }
 
 
        protected void Companies_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == "InitInsert")
            {
                if (UserCanAddCompany) Response.Redirect("NewCompany.aspx?CompanyID=new");
                else e.Canceled = true;
            }
            else if (e.CommandName == "Delete")
            {
                string CompanyHash = ((GridDataItem)e.Item).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["CompanyHash"].ToString();
 
                using (DBAppl dbm = new DBAppl())
                {
                    UOContext con = new UOContext(dbm.GetSqlConnection());
                    con.BeginTransaction();
 
                    try
                    {
                        int reqId = CompanyRequest.DeleteCompanyRequest(Session["UserID"].ToString(), CompanyHash, con);
                        // ModuleManager.RequestAction();
                        con.Commit();
                    }
                    catch (Exception ex)
                    {
                        con.Rollback();
                        logger.Error("DeleteCompany", ex);
                        Response.Redirect("~/Error.aspx", true);
                    }
                }
            }
            else if (e.CommandName == "Edit")
            {
                string CompanyHash = ((GridDataItem)e.Item).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["CompanyHash"].ToString();
                Response.Redirect("Company.aspx?CompanyID=" + CompanyHash);
            }
        }
 
        protected void Companies_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem dataItem = (GridDataItem)e.Item;
                DataRowView row = (DataRowView)e.Item.DataItem;
                int CompanyID = (int)row["CompanyID"];
                string CompanyHash = row["CompanyHash"].ToString();
                string status = row["status"].ToString().Trim();
                int pendingUserChanges = (int)row["pendingUserChanges"];
                int pendingCompanyChanges = (int)row["pendingCompanyChanges"];
                int userCount = (int) row["userCount"];
                bool hasPermissionUserRead = (int)row["hasPermissionUserRead"] == 1;
 
                ImageButton editButton = (ImageButton)dataItem["EditColumn"].Controls[0];
                ImageButton deleteButton = (ImageButton)dataItem["DeleteColumn"].Controls[0];
 
                if (status != "ACT" || pendingCompanyChanges > 0)
                {
                    editButton.Visible = false;
                    deleteButton.Visible = false;
                }
 
                if (pendingUserChanges > 0 || userCount > 0)
                    deleteButton.Visible = false;
 
                if (status != "ACT" || !hasPermissionUserRead)
                {
                    dataItem["CompanyName"].Controls.RemoveAt(0);
                    Label companyName = new Label();
                    companyName.Text = row["Name"].ToString();
                    dataItem["Companyname"].Controls.AddAt(0, companyName);
                }
            }
        }
 
        protected void Companies_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            using (DBAppl dbm = new DBAppl())
            {
 
                // Gets all companies the user has access to (= UserRead)
                SqlCommand command = new SqlCommand("EXEC fa_getAllUserCompanies @UserID,@Filter", dbm.GetSqlConnection());
                SqlParameter sqlParam = new SqlParameter("@UserID", SqlDbType.NVarChar);
                sqlParam.Value = ACL.currentUser;
                command.Parameters.Add(sqlParam);
 
                logger.Debug("Filter=" + searchBox.Text);
                command.Parameters.Add(new SqlParameter("@Filter", searchBox.Text));
 
                SqlDataAdapter adapter = new SqlDataAdapter(command);
                DataTable dt = new DataTable();
                adapter.Fill(dt);
 
                Companies.DataSource = dt;
            }
        }
 
        protected void PendingCompanies_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            using (var dbm = new DBAppl())
            {
                SqlCommand command = new SqlCommand(@"SELECT ci.*, ri.firstName + ' ' + ri.lastName AS Reseller, oi.orderDate
                    FROM [td].[companyImport] ci
                    JOIN [td].[resellerInfo] ri ON ri.fImportId = ci.importId
                    JOIN [td].[orderItem] oi ON oi.fImportId = ci.importId
                    WHERE [status] = 'WAIT'", dbm.GetSqlConnection());
                SqlDataAdapter adapter = new SqlDataAdapter(command);
                DataTable dt = new DataTable();
                adapter.Fill(dt);
 
                PendingCompanies.DataSource = dt;
            }
        }
 
        void Authorize()
        {
            if (!ACL.HasAccess("CompanyDelete"))
                Companies.Columns.FindByUniqueName("DeleteColumn").Visible = false;
        }
    }
}


Regards,
m.

2 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 08 Oct 2013, 08:36 AM
Hello Milan,

Note that the presented issue is caused by a generic IIS configuration and is not related to the RadControls you have into your application. I would suggest you to review the external resources bellow which discuss adding the needed settings for the particular app pool:
http://technet.microsoft.com/en-us/library/cc771956%28v=ws.10%29.aspx
http://stackoverflow.com/questions/3891178/how-to-prevent-extend-idletimeout-in-iis-7
http://stackoverflow.com/questions/1596267/how-to-disable-the-application-pool-idle-time-out-in-iis7


Regards,
Maria Ilieva
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Milan
Top achievements
Rank 1
answered on 14 Oct 2013, 10:37 AM
I guess I was not searching the solution with the right keywords :)
Thank you for the resources!

Regards,m.
Tags
General Discussions
Asked by
Milan
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Milan
Top achievements
Rank 1
Share this question
or