我做了一个自定义绑定Grid,Grid和几个提交值的textbox是放在UpdatePanel里的,但是我提交的时候会弹出一个对话框报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 trace is enabled.Details:Error parsing near '      |<html>          ,. <head>
不知道什么原因,我的cs提交数据的BUTTON事件是:
    protected void BtAddItem_Click(object sender, EventArgs e)
    {
        DataSet ds = new DataSet();
        DataRow dr;
        DataTable dt;
        if (Session["Table"] == null)
        {
                dt = new DataTable("Item");
                dt.Columns.Add("物料号");
                dt.Columns.Add("物料描叙");
                dt.Columns.Add("数量");
                dt.Columns.Add("重量");
                dt.Columns.Add("税收代码");
                dt.Columns.Add("价格");
                dt.Columns.Add("批号");
                dt.Columns.Add("等级");
                dt.Columns.Add("特代");
                dt.Columns.Add("线别");
                dt.Columns.Add("销售单位");
                dt.Columns.Add("来源仓库");
       }
       else
       {
           dt = (DataTable)Session["Table"];
       }
       dr = dt.NewRow();
       dr[0] = txtItemCode.Text;
       dr[1] = txtDscription.Text;
       dr[2] = txtQuantity.Text;
       dr[3] = txtU_zld.Text;
       dr[4] = txtVatGroup.Text;
       dr[5] = txtPrice.Text;
       dr[6] = txtU_LotNo.Text;
       dr[7] = txtU_Grade.Text;
       dr[8] = txtU_Grade_S.Text;
       dr[9] = txtU_LineNo.Text;
       dr[10] = txtU_sf.Text;
       dr[11] = txtU_Dwhscode.Text;
       dt.Rows.Add(dr);       Session["Table"] = dt;
       ds.Merge(dt);
       C1WebGridItem.DataSource = ds.Tables["Item"].DefaultView;
       C1WebGridItem.DataBind();
    }

解决方案 »

  1.   

    补充以上的HTML代码
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Sellfrom.aspx.cs" Inherits="Operation_Sellfrom" %>
    <%@ Register Assembly="C1.Web.Command.2" Namespace="C1.Web.Command" TagPrefix="c1c" %>
    <%@ Register Assembly="C1.Web.C1WebGrid.2" Namespace="C1.Web.C1WebGrid" TagPrefix="C1WebGrid" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>无标题页</title>
          <link href="../css/css.css"  type="text/css" rel="stylesheet" />     
    </head>
    <body style="font-size: 10pt; margin: 0px; font-family: Arial, 宋体; height: 100%; left: 0px; clip: rect(0px auto auto 0px); top: 0px;background-color:#d3dcf5;">
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <asp:UpdatePanel ID="UpdatePanel3" runat="server">
                                    <ContentTemplate>
    <div>                       <table>
                                            <tr>
                                                <td></td>
                                                <td style="width: 3px"><asp:Button ID="Button" runat="server" Text="展开" OnClick="Button2_Click" style="background-image: url(../images/Button2.gif)"  /></td>
                                                <td style="background-image: url(../images/Button_Click.gif); width: 100px">
                                                </td>
                                                <td></td>
                                                <td></td>
                                            </tr>                       
                                        </table></div>
                                     </ContentTemplate>
                                </asp:UpdatePanel>
      

  2.   

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                                    <ContentTemplate> 
                                        <table>
                                            <tr>
                                                <td>
                                                 <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
                            <asp:View ID="View1" runat="server">
                      <fieldset style="width: 980px;">
                        <legend>抬头资料</legend>
                                <table>
                                             <tr>
                                        <td  style="width: 255px;">&nbsp;&nbsp;&nbsp;&nbsp;物料号:<br/> 
                                            &nbsp;&nbsp;&nbsp;&nbsp;<asp:TextBox ID="txtItemCode" runat="server" Width="160px"></asp:TextBox>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                        <td  style="width: 255px;">&nbsp;&nbsp;&nbsp;&nbsp;物料描叙:<br/>
                                            &nbsp;&nbsp;&nbsp;&nbsp;<asp:TextBox ID="txtDscription" runat="server" Width="160px"></asp:TextBox>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                        <td  style="width: 255px;">&nbsp;&nbsp;&nbsp;&nbsp;数量:<br/>
                                            &nbsp;&nbsp;&nbsp;&nbsp;<asp:TextBox ID="txtQuantity" runat="server" Width="160px"></asp:TextBox>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                        <td>&nbsp;&nbsp;&nbsp;&nbsp;重量:<br/>
                                            &nbsp;&nbsp;&nbsp;&nbsp;<asp:TextBox ID="txtU_zld" runat="server" Width="160px"></asp:TextBox>&nbsp;&nbsp;&nbsp;&nbsp;</td>                                </tr>
                                    <tr>
                                        <td>&nbsp;&nbsp;&nbsp;&nbsp;税收代码:<br/>
                                            &nbsp;&nbsp;&nbsp;&nbsp;<asp:TextBox ID="txtVatGroup" runat="server" Width="160px"></asp:TextBox>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                        <td>&nbsp;&nbsp;&nbsp;&nbsp;价格:<br/>
                                            &nbsp;&nbsp;&nbsp;&nbsp;<asp:TextBox ID="txtPrice" runat="server" Width="160px"></asp:TextBox>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                        <td>&nbsp;&nbsp;&nbsp;&nbsp;批号:<br/>
                                            &nbsp;&nbsp;&nbsp;&nbsp;<asp:TextBox ID="txtU_LotNo" runat="server" Width="160px"></asp:TextBox>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                        <td>&nbsp;&nbsp;&nbsp;&nbsp;等级:<br/>
                                            &nbsp;&nbsp;&nbsp;&nbsp;<asp:TextBox ID="txtU_Grade" runat="server" Width="160px"></asp:TextBox>&nbsp;&nbsp;&nbsp;&nbsp;</td>          
                                    </tr>
                                    <tr>
                                        <td>&nbsp;&nbsp;&nbsp;&nbsp;特代:<br/>
                                        &nbsp;&nbsp;&nbsp;&nbsp;<asp:TextBox ID="txtU_Grade_S" runat="server" Width="160px"></asp:TextBox>&nbsp;&nbsp;&nbsp;&nbsp;
                                        </td>
                                        <td>
                                            &nbsp;&nbsp;&nbsp;&nbsp;线别:<br/>
                                            &nbsp;&nbsp;&nbsp;&nbsp;<asp:TextBox ID="txtU_LineNo" runat="server" Width="160px"></asp:TextBox>&nbsp;&nbsp;&nbsp;&nbsp;
                                        </td>
                                        <td>
                                            &nbsp;&nbsp;&nbsp;&nbsp;销售单位:<br/>
                                            &nbsp;&nbsp;&nbsp;&nbsp;<asp:TextBox ID="txtU_sf" runat="server" Width="160px"></asp:TextBox>&nbsp;&nbsp;&nbsp;&nbsp;
                                        </td>
                                        <td>&nbsp;&nbsp;&nbsp;&nbsp;来源仓库:<br/>
                                            &nbsp;&nbsp;&nbsp;&nbsp;<asp:TextBox ID="txtU_Dwhscode" runat="server" Width="160px"></asp:TextBox>&nbsp;&nbsp;&nbsp;&nbsp;</td>                           
                                    </tr> 
                             <tr>
                                        <td style="width: 255px;"> </td>
                                        <td style="width: 255px;"> </td>
                                        <td style="width: 255px;"></td>
                                        <td align="right"><asp:Button ID="Button11" runat="server" Text="展开" OnClick="Button2_Click" style="background-image: url(../images/Button2.gif)" Visible="False"  />
                                        <asp:Button ID="BuAddItem" runat="server" Text="提交" OnClick="BtAddItem_Click" style="background-image: url(../images/Button2.gif)" Visible="False"  />
                                        <asp:Button ID="BuSave" runat="server" Text="保存" OnClick="BuSave_Click" style="background-image: url(../images/Button2.gif)" Visible="False"  /></td> </tr>                 
                                </table>
                                  </fieldset>
                               </asp:View>                      
                        </asp:MultiView> 
                                                </td>  </tr>
                                            <tr>
                                            <td>
                         <asp:MultiView ID="MultiView2" runat="server">
                            <asp:View ID="View2" runat="server">      
                                    <C1WebGrid:C1WebGrid ID="C1WebGridItem" runat="server" BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1" GridLines="None" AllowColMoving="True" AllowColSizing="True" Width="980px">
                                        <FooterStyle BackColor="#C3C6C3" ForeColor="Black" />
                                        <SelectedItemStyle BackColor="#9471DE" ForeColor="White" />
                                        <ItemStyle BackColor="#DEDFDE" ForeColor="Black" />
                                        <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
                                        <HeaderStyle BackColor="#4A3C8E" Font-Bold="True" ForeColor="#E7E7FF" />
                                    </C1WebGrid:C1WebGrid>                            
                                     </asp:View>                      
                        </asp:MultiView> </td>
                                            <tr>
                                         </table>           
                        </ContentTemplate>
                                </asp:UpdatePanel>  
        </form>
    </body>
    </html>继续补充HTML代码
      

  3.   

    把button 放到updatepanel 外面试试
    异步更新的代码经过特殊的处理.后台识别不了
      

  4.   

    我如果把Button放在updatepanel那怎么实现异步刷新?
      

  5.   

    http://weblogs.asp.net/leftslipper/archive/2007/02/26/sys-webforms-pagerequestmanagerparsererrorexception-what-it-is-and-how-to-avoid-it.aspx
      

  6.   

    偶尔我一上弹出个框显示这个
    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 trace is enabled.Details:Error parsing near '      |<html>          ,. <head>偶尔会显示出来,偶尔他又不现实
      

  7.   

    我记得UpdatePanel 写Session好像是会出现异常的.
    你不传session 试试。
      

  8.   

    不会吧?一个页面怎么可能没Session?
      

  9.   

    Add a PostBackTrigger to your UpdatePanel that points at the button. This works great if the button is declared statically through up on the page.
      

  10.   

    你的代码中没有Respose.Write(),有Session,那就是因为可能Session丢失发出的异常,时有时无.
    具体分析参考如下(来源网上):
    ASP.NET中使用AJAX后,Session丢失异常的自定义处理。ASP.NET中使用AJAX后,如果客户端长时间没有操作或者服务器原因丢失Session,会弹出类似以下的英文错误信息,对于用户没有实际提示作用。为了有更好的用户体验,我们希望能够自定义这个异常。
     引用内容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 '下面提供一个很简单的办法,使用ScriptManager的EndRequestHandler事件。将以下Javascript加入到<ScriptManager>标签后面,注意不能放在<Head>中。
     程序代码<script language="javascript"> Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler); 
    function EndRequestHandler(sender, args) 

    if (args.get_error() != undefined) 

    if(args.get_error().message.substring(0, 51) == "Sys.WebForms.PageRequestManagerParserErrorException") 
    {
    window.location.reload(); //出现Session丢失时的错误处理,可以自己定义。

    else
    {
    alert("发生错误!原因可能是数据不完整,或网络延迟。"); //其他错误的处理。
    }
    args.set_errorHandled(true); 
    }

    </script> 
      

  11.   

    不要用Session,用ViewState应该可以解决你的问题。
      

  12.   

    http://pohee.com/general/sys-webforms-pagerequestmanagerparsererrorexception-in-ms-ajax/不可用
    Response.Write() 
    Response.......
      

  13.   

    不用SESSION就能解决这个问题了,用其他方式都可以保存的,COOKIES和MemberShip机制也可以的,而且性能上面会高很多,觉得Cookies安全性不好,加密下就好了,能不用会话就不用,很容易丢失和占用CPU的内存
      

  14.   

    使用微软的Ajax框架后不要用response.write()弹出提示框,用下面这个:
    ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "updateScript", "alert('保存成功');", true);
      

  15.   

    把你的button按钮放在外面就可以了
      

  16.   

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <Triggers>
            <asp:PostBackTrigger ControlID="btn_Login" />
        </Triggers>
    用这个指定一下你的按钮就好使了
      

  17.   

    EnableEventValidation="false" page头里加入这个就可以啦。我就是这样的。可以正确使用哒