2012-07-11 115 views
3

我,迫切需要調試的幫助,一直停留在這個錯誤現在6天.....調試:微軟JScript運行時錯誤

錯誤我在ASp.net的應用程序得到的是:

Microsoft JScript runtime 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 '<script type='text/j'. 

下面是相關的代碼片段,

CollyDataExchangeWebService Col_ValSub = new CollyDataExchangeWebService(); 
    CollyReportServiceRequest ServiceReq = new CollyReportServiceRequest(); 
    CollyReportServiceRequestData ServiceReqData = new CollyReportServiceRequestData(); 

    ServiceReqData.AmendmentIndicatorSpecified = true; 
    ServiceReqData.AmendmentIndicator = false; 

    ServiceReqData.CollyReport = ColRep; 
    ServiceReq.ServiceRequestData = ServiceReqData; 
    ServiceReq.ServiceRequestHeader = ServiceHeader; 

    errValidate = null; 

    //btnOK.OnClientClick = "MSGShow()"; 
    bool Valid = true; 
    string ErrMsgs = ""; 

    if (((System.Web.UI.WebControls.Button)(sender)).CommandArgument == "Validate") 
    { 
     CollyReportServiceResponse ValResponse = Col_ValSub.validateReport(ServiceReq); 


     switch (ValResponse.ServiceResponseHeader.ServiceStatus) 
     { 
      case ServiceStatus.Successful: 

       btnOK.OnClientClick = ""; 
       valHeader.Text = "Validation is Completed. No errors were found"; 
       mlValPopup.Show(); 

       break; 

      case ServiceStatus.ValidationErrors: 
       Valid = false; 
       ErrMsgs = ErrMsgs + _ValidationError(ValResponse); 
       ValBTN.Update(); 
       mlValPopup.Show(); 
       break; 

      case ServiceStatus.SystemError: 
       btnOK.OnClientClick = ""; 
       Valid = false; 
       ErrMsgs = ErrMsgs + _SystemError(ValResponse); 
       ValBTN.Update(); 
       mlValPopup.Show(); 
       break; 
     } 

後調試的時間,我發現這條線將導致錯誤:

CollyReportServiceResponse ValResponse = Col_ValSub.validateReport(ServiceReq); 

經過6天的調試和沮喪,我發現有些記錄導致這個問題,其他人不在OLDER版本的代碼中,但在新版本中所有的記錄導致這個錯誤,所以它必須做的東西與數據在數據庫這意味着代碼中的某些方法行爲不同的空值,但我無法找出究竟是什麼問題,因爲我的應用程序是3萬行代碼

經過搜索和嘗試各種解決方案後,下面的2不是解決我的問題。

forums.asp.net/t/1357862.aspx http://www.vbforums.com/showthread.php?t=656246

我想提一提,我已經有,因爲它是由那些早已過去留下其他程序員困難的時間來處理這個應用程序背後沒有文件或評論意大利麪代碼。

我沒有這個代碼但是從過去的其他程序員已經把回覆於代碼:

private void MessageBox(string msg) 
    { 
     if (!string.IsNullOrEmpty(msg)) 
     { 
      Global.tmpmsg = msg; 
      msg = null; 
     } 
     Response.Write("<script type=\"text/javascript\" language=\"javascript\">"); 
     Response.Write("window.open('ErrorPage.aspx?msg=" + "','PopUp','screenX=0,screenY=0,width=700,height=340,resizable=1,status=no,scrollbars=yes,toolbars=no');"); 
     Response.Write("</script>"); 

    } 

這一個是在另一種方法:

 Response.Write("<script type=\"text/javascript\" language=\"javascript\">"); 
     Response.Write("alert('No search resuls were found');"); 
     Response.Write("</script>"); 

或本:

if (!string.IsNullOrEmpty(msg)) 
{ 
    Global.tmpmsg = msg; 
    Response.Write("<script type=\"text/javascript\" language=\"javascript\">"); 
    Response.Write("window.open('ErrorPage.aspx?msg=" + "','PopUp','screenX=0,screenY=0,width=700,height=340,resizable=1,status=no,scrollbars=yes,toolbars=no');"); 
    Response.Write("</script>"); 
} 

Jrummel的評論之後,我將其添加到代碼中,然後什麼都沒有發生。

private void MessageBox(string msg) 
{/* 
    if (!string.IsNullOrEmpty(msg)) 
    { 
     Global.tmpmsg = msg; 
     msg = null; 
    } 
    Response.Write("<script type=\"text/javascript\" language=\"javascript\">"); 
    Response.Write("window.open('ErrorPage.aspx?msg=" + "','PopUp','screenX=0,screenY=0,width=700,height=340,resizable=1,status=no,scrollbars=yes,toolbars=no');"); 
    Response.Write("</script>"); 
    */ 
// Define the name and type of the client scripts on the page. 
String csname1 = "PopupScript"; 
Type cstype = this.GetType(); 

// Get a ClientScriptManager reference from the Page class. 
ClientScriptManager cs = Page.ClientScript; 

// Check to see if the startup script is already registered. 
if (!cs.IsStartupScriptRegistered(cstype, csname1)) 
{ 
    String cstext1 = "<script type=\"text/javascript\" language=\"javascript\">" + " " + "window.open('ErrorPage.aspx?msg=" + "','PopUp','screenX=0,screenY=0,width=700,height=340,resizable=1,status=no,scrollbars=yes,toolbars=no');" + " " + "</script>"; 
    cs.RegisterStartupScript(cstype, csname1, cstext1, false); 
} 



} 
+1

我沒有看到錯誤和代碼段之間的任何關係。 '

1

請勿使用Response.Write() 請改爲創建一個 LiteralControl並將其添加到頁面。

使用ClientScriptManager將腳本添加到頁面。下面是從MSDN的例子:

// Define the name and type of the client scripts on the page. 
String csname1 = "PopupScript"; 
Type cstype = this.GetType(); 

// Get a ClientScriptManager reference from the Page class. 
ClientScriptManager cs = Page.ClientScript; 

// Check to see if the startup script is already registered. 
if (!cs.IsStartupScriptRegistered(cstype, csname1)) 
{ 
    String cstext1 = "alert('Hello World');"; 
    cs.RegisterStartupScript(cstype, csname1, cstext1, true); 
} 
+0

@jrumell您能不能詳細闡述一下,我對ASP.net或任何這些response.write方法都不太熟悉。 – Bulvak 2012-07-11 13:10:38

+0

我添加了一個例子。 – jrummell 2012-07-11 13:12:28

+0

@jrumell編輯後我更新了帖子,現在看來什麼也沒有發生,這不是想要的行爲。 – Bulvak 2012-07-11 13:33:38

相關問題