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

Clicking on add new record Sys.WebForms.PageRequestManagerParserErrorException: Th

0 Answers 59 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
mathieu cupryk
Top achievements
Rank 1
mathieu cupryk asked on 07 Aug 2012, 12:37 AM
Line: 9
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 '

When I click on add record it gives me the above error.



<%@ Page Title="" Language="C#" MasterPageFile="~/App_MasterPages/OneColumnMasterPage.Master"
    AutoEventWireup="true" CodeBehind="AddModifyType.aspx.cs" Inherits="Schedule.Administration.AddModifyType" %>
  
<asp:Content ID="Content1" ContentPlaceHolderID="HeadPlaceHolder" runat="server">
    <style type="text/css">
        .EditFormHeader td
        {
            font-size: 14px;
            padding: 4px !important;
            font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif;
            color: #646882;
            text-decoration: none;
            font-weight: bold;
            height: 22px;
            border: 1 px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <br />
    <table cellpadding="3" cellspacing="0" border="0" style="width: 100%;">
        <tr>
            <td id="header">
                <SCHEDULE:uxPageTitle ID="uxPageTitle" Title="Add/Modify Type" runat="server"></SCHEDULE:uxPageTitle>
                <table border="0" cellpadding="0" cellspacing="0" width="100%" class="box">
                    <tr class="boxTop">
                        <td>
                            <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
                            </telerik:RadCodeBlock>
                            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                                <AjaxSettings>
                                    <telerik:AjaxSetting AjaxControlID="RadGrid1">
                                        <UpdatedControls>
                                            <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                                            <telerik:AjaxUpdatedControl ControlID="divMsgs" />
                                        </UpdatedControls>
                                    </telerik:AjaxSetting>
                                </AjaxSettings>
                            </telerik:RadAjaxManager>
                            <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
                            </telerik:RadAjaxLoadingPanel>
                            <input type="hidden" id="radGridClickedRowIndex" name="radGridClickedRowIndex" />
                            <telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
                                Skin="Windows7" AllowPaging="True" ShowStatusBar="True" OnPreRender="RadGrid1_PreRender"
                                OnNeedDataSource="RadGrid1_NeedDataSource" OnUpdateCommand="RadGrid1_UpdateCommand"
                                OnInsertCommand="RadGrid1_InsertCommand" OnDeleteCommand="RadGrid1_DeleteCommand"
                                CellSpacing="0" GridLines="None" OnItemCreated="RadGrid1_ItemCreated" 
                                OnItemDataBound="RadGrid1_ItemDataBound" onitemcommand="RadGrid1_ItemCommand">
                                <HeaderStyle Font-Bold="True" Font-Size="9pt"></HeaderStyle>
                                <ItemStyle Font-Size="8.5pt" />
                                <AlternatingItemStyle Font-Size="8.5pt" />
                                <PagerStyle Mode="NextPrevAndNumeric" />
                                <ClientSettings>
                                    <Selecting AllowRowSelect="True"></Selecting>
                                </ClientSettings>
                                <ClientSettings>
                                    <Selecting CellSelectionMode="None" AllowRowSelect="True"></Selecting>
                                </ClientSettings>
                                <MasterTableView Width="100%" TableLayout="Auto" CommandItemDisplay="Top" DataKeyNames="Type">
                                    <Columns>
                                        <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" ButtonType="ImageButton"
                                            HeaderStyle-Width="24" EditImageUrl="../Skins/Outlook/Grid/Edit.gif">
                                        </telerik:GridEditCommandColumn>
                                        <telerik:GridBoundColumn DataField="Type" DataType="System.Int32" ItemStyle-Width="7px"
                                            HeaderText="Type" SortExpression="Type" UniqueName="Type">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="TypeDescription" ItemStyle-Width="220px" HeaderText="Description"
                                            SortExpression="TypeDescription" UniqueName="TypeDescription">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="MinLbsGVW" ItemStyle-Width="15px" HeaderText="Min Lbs GVW"
                                            SortExpression="MinLbsGVW" UniqueName="MinLbsGVW">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="MaxLbsGVW" ItemStyle-Width="15px" HeaderText="Max Lbs GVW"
                                            SortExpression="MaxLbsGVW" UniqueName="MaxLbsGVW">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="ReportClassification" ItemStyle-Width="95px"
                                            HeaderText="Report Class" SortExpression="ReportClassification" UniqueName="ReportClassification">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="L_H_S" ItemStyle-Width="10px" HeaderText="L/H/S"
                                            SortExpression="L_H_S" UniqueName="L_H_S">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="RepModel" ItemStyle-Width="40px" HeaderText="Replacement Model"
                                            SortExpression="RepModel" UniqueName="RepModel">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="AmortizationClassification" HeaderText="Amortization Class"
                                            SortExpression="AmortizationClassification" ItemStyle-Width="60px" UniqueName="AmortizationClassification">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="CountClass" ItemStyle-Width="10px" HeaderText="Count Class"
                                            SortExpression="CountClass" UniqueName="CountClass">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="RepCost" DataType="System.Decimal" ItemStyle-Width="60px"
                                            DataFormatString="{0:C}" HeaderText="Replacement Cost" SortExpression="RepCost"
                                            UniqueName="RepCost">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="LeadTimeRequired" HeaderText="Lead Time" SortExpression="LeadTimeRequired"
                                            Visible="false" UniqueName="LeadTimeRequired">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridCheckBoxColumn DataField="HasTires" DataType="System.Boolean" ItemStyle-Width="10px"
                                            HeaderText="Tires" SortExpression="HasTires" UniqueName="HasTires">
                                        </telerik:GridCheckBoxColumn>
                                        <telerik:GridCheckBoxColumn DataField="FirstAidKitRequired" DataType="System.Boolean"
                                            ItemStyle-Width="10px" HeaderText="First Aid" SortExpression="FirstAidKitRequired"
                                            UniqueName="FirstAidKitRequired">
                                        </telerik:GridCheckBoxColumn>
                                        <telerik:GridBoundColumn DataField="FireExtinguisherSize" Visible="false" HeaderText="Fire Exting. Size"
                                            SortExpression="FireExtinguisherSize" UniqueName="FireExtinguisherSize">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="CAMFM" ItemStyle-Width="17px" HeaderText="CAMFM"
                                            SortExpression="CAMFM" UniqueName="CAMFM">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="EffectiveDate" DataType="System.DateTime" DataFormatString="{0:yyyy/MM/dd}"
                                            ItemStyle-Width="20px" HeaderText="Effective Date" SortExpression="EffectiveDate"
                                            Visible="false" UniqueName="EffectiveDate">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="CreatorID" Visible="false" ReadOnly="true" HeaderText="CreatorID"
                                            SortExpression="CreatorID" UniqueName="CreatorID">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="LastModifyID" Visible="false" ReadOnly="true"
                                            HeaderText="Modify By" SortExpression="LastModifyID" UniqueName="LastModifyID">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="LastModifyTime" Visible="false" ReadOnly="true"
                                            DataType="System.DateTime" HeaderText="Modify Time" SortExpression="LastModifyTime"
                                            UniqueName="LastModifyTime">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridButtonColumn ConfirmText="Are you sure you want to delete this record?"
                                            ButtonType="ImageButton" ImageUrl="../Skins/Outlook/Grid/Delete.gif" CommandName="Delete"
                                            Text="Delete" UniqueName="DeleteColumn">
                                            <HeaderStyle Width="20px" />
                                        </telerik:GridButtonColumn>
                                    </Columns>
                                    <EditFormSettings UserControlName="~/Controls/Type/uxAddModifyType.ascx" EditFormType="WebUserControl">
                                        <EditColumn UniqueName="EditCommandColumn1">
                                        </EditColumn>
                                    </EditFormSettings>
                                </MasterTableView>
                                <FilterMenu EnableImageSprites="False">
                                </FilterMenu>
                            </telerik:RadGrid>
                            <br />
                            <br />
                            <p id="divMsgs" runat="server">
                                  <asp:Label ID="Label1" runat="server" EnableViewState="False" Font-Bold="True"
                                    ForeColor="#FF8080"></asp:Label>
                                  <asp:Label ID="Label2" runat="server" EnableViewState="False" Font-Bold="True"
                                    ForeColor="#00C000"></asp:Label>
                            </p>
                            <br />
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ModalPlaceHolder" runat="server">
</asp:Content>
  
using System;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using System.Data;
using System.Collections;
using System.Configuration;
using System.Data.SqlClient;
using System.Globalization;
using System.Security.Principal;
using Schedule.Helpers;
  
namespace Schedule.Administration
{
    public partial class AddModifyType : ScheduleBasePage
    {
          #region Data members
  
  
        #endregion
  
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
  
  
            }
  
        }
  
        private static DataTable GetDataTable(string queryString)
        {
            String ConnString = ConfigurationManager.ConnectionStrings["MinotaurConnectionString"].ConnectionString;
            SqlConnection MySqlConnection = new SqlConnection(ConnString);
            SqlDataAdapter MySqlDataAdapter = new SqlDataAdapter();
            MySqlDataAdapter.SelectCommand = new SqlCommand(queryString, MySqlConnection);
  
            DataTable myDataTable = new DataTable();
            MySqlConnection.Open();
            try
            {
                MySqlDataAdapter.Fill(myDataTable);
            }
            finally
            {
                MySqlConnection.Close();
            }
  
            return myDataTable;
        }
  
        protected void RadGrid1_DeleteCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            string ID = (e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Type"].ToString();
            DataTable typeTable = this.SqlDataSourceTypesDataTable;
            try
            {
                if (typeTable.Rows.Find(ID) != null)
                {
                    typeTable.Rows.Find(ID).Delete();
                    typeTable.AcceptChanges();
                    DisplayMessage(false, "Your Type has been deleted successfully!");
                }
            }
            catch (Exception ex)
            {
  
                DisplayMessage(true, "Your Type could not be deleted. Reason: " + ex.Message);
                e.Canceled = true;
            }
  
  
        }
  
        private DataTable SqlDataSourceTypesDataTable
        {
            get
            {
                object obj = this.Session["ModifyTypes"];
                if ((!(obj == null)))
                {
                    return ((DataTable)(obj));
                }
                DataTable myDataTable = new DataTable();
                myDataTable = GetDataTable("SELECT Type, TypeDescription, MinLbsGVW, MaxLbsGVW, ReportClassification, [L/H/S], RepModel, AmortizationClassification, CountClass,RepCost, LeadTimeRequired, HasTires, FirstAidKitRequired, CAMFM, EffectiveDate, CreatorID, LastModifyID, LastModifyTime from Types");
                this.Session["ModifyTypes"] = myDataTable;
                return myDataTable;
            }
        }
  
  
        protected void RadGrid1_UpdateCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;
            UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
            int rowindex = editedItem.ItemIndex;  //Row index to identify the row edited
  
  
            String selectQuery = String.Format("Type='{0}'",
            editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["Type"]);
  
  
            DataRow[] changedRows = this.SqlDataSourceTypesDataTable.Select(selectQuery);
  
            if (changedRows.Length != 1)
            {
                RadGrid1.Controls.Add(new LiteralControl("Unable to locate the row for updating."));
                e.Canceled = true;
                return;
            }
  
            string domainUser = null;
            WindowsIdentity userName = WindowsIdentity.GetCurrent();
  
  
            if (userName != null)
            {
                domainUser = StringManipulation.ExtractUserName(userName.Name.ToString());
            }
  
            //Update new values
            Hashtable newValues = new Hashtable();
            newValues["Type"] = (userControl.FindControl("txtTypeNumber") as TextBox).Text;
            newValues["TypeDescription"] = (userControl.FindControl("txtTypeDescription") as TextBox).Text;
            newValues["MinLbsGVW"] = (userControl.FindControl("txtMinLbsGVW") as TextBox).Text;
            newValues["MaxLbsGVW"] = (userControl.FindControl("txtMaxLbsGVW") as TextBox).Text;
            newValues["ReportClassification"] = (userControl.FindControl("txtReportClassification") as TextBox).Text;
            newValues["L/H/S"] = (userControl.FindControl("txtLHS") as TextBox).Text;
            newValues["RepModel"] = (userControl.FindControl("txtReplacementModel") as TextBox).Text;
            newValues["AmortizationClassification"] = (userControl.FindControl("txtAmortization") as TextBox).Text;
            newValues["CountClass"] = (userControl.FindControl("txtCountClass") as TextBox).Text;
            newValues["RepCost"] = double.Parse(((userControl.FindControl("txtReplacementCost") as TextBox).Text), NumberStyles.Currency); 
            newValues["LeadTimeRequired"] = 0;
            newValues["HasTires"] = (userControl.FindControl("chkHasTires") as CheckBox).Checked;
            newValues["FirstAidKitRequired"] = (userControl.FindControl("chkFirstAid") as CheckBox).Checked;
            newValues["CAMFM"] = (userControl.FindControl("txtCAMFM") as TextBox).Text;
            newValues["EffectiveDate"] = (userControl.FindControl("lblEffectiveDate") as Label).Text;
            newValues["CreatorID"] = (userControl.FindControl("lblEffectiveDate") as Label).Text;
            newValues["LastModifyID"] = domainUser;// (userControl.FindControl("lblModifiedBy") as Label).Text;
            newValues["LastModifyTime"] = DateTime.Now;
  
            changedRows[0].BeginEdit();
            try
            {
                foreach (DictionaryEntry entry in newValues)
                {
                    changedRows[0][(string)entry.Key] = entry.Value;
                }
                changedRows[0].EndEdit();
                this.SqlDataSourceTypesDataTable.AcceptChanges();
  
                DisplayMessage(false, "Your Type has been updated successfully!");
  
            }
            catch (Exception ex)
            {
  
                changedRows[0].CancelEdit();
                DisplayMessage(true, "Your Type could not be updated. Reason: " + ex.Message);
                e.Canceled = true;
            }
  
  
        }
  
        private void DisplayMessage(bool isError, string text)
        {
            Label label = (isError) ? this.Label1 : this.Label2;
            label.Text = text;
        }
  
  
        protected void RadGrid1_InsertCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.PerformInsertCommandName)
            {
  
                GridEditableItem editedItem = e.Item as GridEditableItem;
                UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
  
                //Create new row in the DataSource
                DataRow newRow = this.SqlDataSourceTypesDataTable.NewRow();
  
  
                string domainUser = null;
                WindowsIdentity userName = WindowsIdentity.GetCurrent();
  
  
                if (userName != null)
                {
                    domainUser = StringManipulation.ExtractUserName(userName.Name.ToString());
                }
  
                //Insert new values
                Hashtable newValues = new Hashtable();
                newValues["Type"] = (userControl.FindControl("txtTypeNumber") as TextBox).Text;
                newValues["TypeDescription"] = (userControl.FindControl("txtTypeDescription") as TextBox).Text;
                newValues["MinLbsGVW"] = (userControl.FindControl("txtMinLbsGVW") as TextBox).Text;
                newValues["MaxLbsGVW"] = (userControl.FindControl("txtMaxLbsGVW") as TextBox).Text;
                newValues["ReportClassification"] = (userControl.FindControl("txtReportClassification") as TextBox).Text;
                newValues["L/H/S"] = (userControl.FindControl("txtLHS") as TextBox).Text;
                newValues["RepModel"] = (userControl.FindControl("txtReplacementModel") as TextBox).Text;
                newValues["AmortizationClassification"] = (userControl.FindControl("txtAmortization") as TextBox).Text;
                newValues["CountClass"] = (userControl.FindControl("txtCountClass") as TextBox).Text;
                newValues["RepCost"] = double.Parse(((userControl.FindControl("txtReplacementCost") as TextBox).Text), NumberStyles.Currency);
                newValues["LeadTimeRequired"] = 0;
                newValues["HasTires"] = (userControl.FindControl("chkHasTires") as CheckBox).Checked;
                newValues["FirstAidKitRequired"] = (userControl.FindControl("chkFirstAid") as CheckBox).Checked;
                newValues["CAMFM"] = (userControl.FindControl("txtCAMFM") as TextBox).Text;
                newValues["EffectiveDate"] = (userControl.FindControl("lblEffectiveDate") as Label).Text;
                newValues["CreatorID"] = domainUser; // (userControl.FindControl("lblEffectiveDate") as Label).Text;
                newValues["LastModifyID"] = domainUser; // (userControl.FindControl("lblModifiedBy") as Label).Text;
                newValues["LastModifyTime"] = DateTime.Now;
  
  
                ////make sure that unique primary key value is generated for the inserted row 
                // newValues["Type"] = (int)this.SqlDataSourceTypeDataTable.Rows[this.SqlDataSourceTypeDataTable.Rows.Count - 1]["Type"] + 1;
  
  
  
                try
                {
                    foreach (DictionaryEntry entry in newValues)
                    {
                        newRow[(string)entry.Key] = entry.Value;
                    }
                    this.SqlDataSourceTypesDataTable.Rows.Add(newRow);
                    this.SqlDataSourceTypesDataTable.AcceptChanges();
  
                    DisplayMessage(false, "Your Type has been inserted successfully!");
  
                }
                catch (Exception ex)
                {
  
                    DisplayMessage(true, "Your Type could not be inserted. Reason: " + ex.Message);
                    e.Canceled = true;
                }
            }
        }
  
        protected void RadGrid1_PreRender(object sender, System.EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this.RadGrid1.MasterTableView.Items[1].Edit = true;
                this.RadGrid1.MasterTableView.Rebind();
            }
        }
  
  
        protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
        {
            if (e.Column.IsBoundToFieldName("Date"))
            {
                (e.Column as GridDateTimeColumn).DataFormatString = "{0:D}";
            }
            else if (e.Column.IsBoundToFieldName("UnitPrice"))
            {
                (e.Column as GridNumericColumn).DataFormatString = "{0:C}";
            }
            if (e.Column is GridBoundColumn)
            {
                (e.Column as GridBoundColumn).FilterControlWidth = System.Web.UI.WebControls.Unit.Pixel(100);
            }
        }
  
        protected void RadGrid1_EditCommand(object sender, GridCommandEventArgs e)
        {
  
        }
  
        protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            this.RadGrid1.DataSource = this.SqlDataSourceTypesDataTable;
            this.SqlDataSourceTypesDataTable.PrimaryKey = new DataColumn[] 
                {
                  this.SqlDataSourceTypesDataTable.Columns["Type"]
                };
  
        }
  
        protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
        {
            //if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
            //{
            //    UserControl MyUserControl = e.Item.FindControl(GridEditFormItem.EditFormUserControlID) as UserControl;
            //    string script = String.Format("$get('{0}').focus(); $get('{0}').select();", MyUserControl.FindControl("TextBox7").ClientID);
            //    ScriptManager.RegisterStartupScript(Page, typeof(Page), "myscript", script, true);
            //}
  
             
  
        }
  
        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            {
                GridEditableItem editedItem = e.Item as GridEditableItem;
                UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
                TextBox dataField = (userControl.FindControl("txtTypeDescription") as TextBox); 
                dataField.Focus();
            }
        }
  
        protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.InitInsertCommandName)
            {
                //Add new" button clicked
                e.Canceled = true;
                //Prepare an IDictionary with the predefined values
                System.Collections.Specialized.ListDictionary newValues = new
                System.Collections.Specialized.ListDictionary();
                newValues["Type"] = "0";
                //Insert the item and rebind
                e.Item.OwnerTableView.InsertItem(newValues);
            }
  
        }
  
  
  
    }
  
     
}

No answers yet. Maybe you can help?

Tags
Ajax
Asked by
mathieu cupryk
Top achievements
Rank 1
Share this question
or