简体   繁体   English

使用Server.Transfer进行重定向期间出错,无法解析从服务器收到的消息。

[英]Error during Redirection using Server.Transfer 'The message received from the server could not be parsed.'

I'm trying to redirect to Transaction.aspx Page using Server.Transfer by clicking a link button inside the gridview, this is all happening in the OnRowCommand event. 我试图通过单击gridview内的链接按钮使用Server.Transfer重定向到Transaction.aspx页面,这一切都发生在OnRowCommand事件中。 Code for link button is 链接按钮的代码为

<asp:TemplateField Visible="true" HeaderText="" ShowHeader="false">
                                            <ItemTemplate>
                                                <asp:LinkButton ID="btnRedirect" runat="server" CommandArgument='<%# Bind("ID") %>' CommandName="CompleteTransaction" Text="Complete Transaction"></asp:LinkButton>
                                            </ItemTemplate>
                                        </asp:TemplateField>

And here is the C# code 这是C#代码

 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("CompleteTransaction"))
        {
            int rowIndex = Convert.ToInt32(e.CommandArgument); // Get the current row                
            GridViewRow selectedRow = GridView1.Rows[rowIndex - 1];
            Label lblServiceType = (Label)selectedRow.FindControl("lblServiceType");
            Label lblMethod = (Label)selectedRow.FindControl("lblMethod");
            Label lblSource = (Label)selectedRow.FindControl("lblSource");
            Label lblAmount = (Label)selectedRow.FindControl("lblAmount");
            string donorName = selectedRow.Cells[7].Text;
            string contactNo = Convert.ToString(GridView1.DataKeys[rowIndex - 1].Values[1]);
            string province = Convert.ToString(GridView1.DataKeys[rowIndex - 1].Values[2]);
            string city = Convert.ToString(GridView1.DataKeys[rowIndex - 1].Values[3]);
            string address = Convert.ToString(GridView1.DataKeys[rowIndex - 1].Values[4]);
            string donorId = Convert.ToString(GridView1.DataKeys[rowIndex - 1].Values[5]);
            string id = Convert.ToString(GridView1.DataKeys[rowIndex - 1].Values[0]);

            List<string> list = new List<string>();
            list.Add(lblServiceType.Text);
            list.Add(lblMethod.Text);
            list.Add(lblSource.Text);
            list.Add(lblAmount.Text);
            list.Add(donorName);
            list.Add(contactNo);
            list.Add(province);
            list.Add(city);
            list.Add(address);
            list.Add(donorId);
            list.Add(Convert.ToString(rowIndex));

            Session["Controls"] = list;
            Server.Transfer("~/Transaction.aspx");    
        }
    }

If I click on the link button I get the following error in console window 如果单击链接按钮,则会在控制台窗口中出现以下错误

Uncaught Error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.
at Function.Error$create [as create] (ScriptResource.axd?d=D9drwtSJ4hBA6O8UhT6CQjvFd3OFr4OSn3jDIa_YkBYl_kDCdss53aQGXnuBrrAQMiPFhRMC1uQCNM…:237)
at Sys$WebForms$PageRequestManager$_createPageRequestManagerParserError [as _createPageRequestManagerParserError] (ScriptResource.axd?d=JnUc-DEDOM5KzzVKtsL1tdEX-qt8s9RxtGk2vMlQxGrK2fF3ftonwGzhez_pN-OzkVlcWDlUr8Qv6P…:665)
at Sys$WebForms$PageRequestManager$_parseDelta [as _parseDelta] (ScriptResource.axd?d=JnUc-DEDOM5KzzVKtsL1tdEX-qt8s9RxtGk2vMlQxGrK2fF3ftonwGzhez_pN-OzkVlcWDlUr8Qv6P…:1435)
at Sys$WebForms$PageRequestManager$_onFormSubmitCompleted [as _onFormSubmitCompleted] (ScriptResource.axd?d=JnUc-DEDOM5KzzVKtsL1tdEX-qt8s9RxtGk2vMlQxGrK2fF3ftonwGzhez_pN-OzkVlcWDlUr8Qv6P…:1314)
at Array.<anonymous> (ScriptResource.axd?d=D9drwtSJ4hBA6O8UhT6CQjvFd3OFr4OSn3jDIa_YkBYl_kDCdss53aQGXnuBrrAQMiPFhRMC1uQCNM…:47)
at ScriptResource.axd?d=D9drwtSJ4hBA6O8UhT6CQjvFd3OFr4OSn3jDIa_YkBYl_kDCdss53aQGXnuBrrAQMiPFhRMC1uQCNM…:3484
at Sys$Net$WebRequest$completed [as completed] (ScriptResource.axd?d=D9drwtSJ4hBA6O8UhT6CQjvFd3OFr4OSn3jDIa_YkBYl_kDCdss53aQGXnuBrrAQMiPFhRMC1uQCNM…:6373)
at XMLHttpRequest.Sys$Net$XMLHttpExecutor._onReadyStateChange (ScriptResource.axd?d=D9drwtSJ4hBA6O8UhT6CQjvFd3OFr4OSn3jDIa_YkBYl_kDCdss53aQGXnuBrrAQMiPFhRMC1uQCNM…:5993)

Also if I use try catch for following exception is thrown 另外,如果我使用try catch引发以下异常

Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.

Your template field is missing the argument. 您的模板字段缺少参数。

<asp:TemplateField>
  <ItemTemplate>
    <asp:Button ID="btnRedirect" runat="server" 
      CommandName="CompleteTransaction" 
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" PostBackUrl="~/WebForm2.aspx"
      Text="Complete Transaction" />
  </ItemTemplate> 
</asp:TemplateField>

In the GridviewRowcommand Event 在GridviewRowcommand事件中

{
//at the end
 Session["Controls"] = list;
 Response.Redirect("~/WebForm2.aspx",false);
}

And in the next page ie in the redirected page add the below code in the form load. 然后在下一页,即重定向页面中,在表单加载中添加以下代码。

     protected void Page_Load(object sender, EventArgs e)
            {
            Page previousPage = Page.PreviousPage;
            if (previousPage != null && previousPage.IsCrossPagePostBack)
            {
                lblName.ServiceType = ((Label)previousPage.FindControl("lblServiceType")).Text;
                lblEmail.Method= ((Label)previousPage.FindControl("lblMethod")).Text;
                //etc bind the remaining label from the previous page
            }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决错误:无法解析从服务器收到的消息 - How to fix error: The message received from the server could not be parsed .NET WebApi中的Server.Transfer /重定向 - Server.Transfer/Redirection in .NET WebApi ASP.NET-无法解析从服务器收到的消息 - ASP.NET - The message received from the server could not be parsed 下载Excel文件onclick,“无法解析从服务器收到的消息” - Download excel file onclick, “The message received from the server could not be parsed” Sys.WebForms.PageRequestManagerParserErrorException:无法解析从服务器收到的消息 - Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed 显示pdf时出错:Sys.WebForms.PageRequestManagerParserErrorException:无法解析从服务器收到的消息 - Error when displaying pdf: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed 在ajax请求上,我们收到此错误:Sys.WebForms.PageRequestManagerParserErrorException:无法解析从服务器收到的消息 - On ajax request we get this error:Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed 使用Server.Transfer()返回时获取错误 - Getting Error while returning back using Server.Transfer() Server.Transfer到HttpHandler - Server.Transfer to an HttpHandler <form>使用Server.Transfer()时的操作 - <form> action when using Server.Transfer()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM