title: Debugging: Microsoft JScript runtime error
body: <p>I am desperately in need of debugging help, been stuck at this error for 6 days now.....</p>
  
  <p>the error I get in my ASp.net app is :</p>
  
  <pre><code>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 '&lt;script type='text/j'.
  </code></pre>
  
  <p>Below is the relevant code snippet, </p>
  
  <pre><code>    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;
          }
  </code></pre>
  
  <p>After hours of debugging I found this line to be causing the error:</p>
  
  <pre><code>CollyReportServiceResponse ValResponse = Col_ValSub.validateReport(ServiceReq);
  </code></pre>
  
  <p>After 6 days of debugging and frustration I found that SOME records cause this issue and others dont in OLDER versions of the code but in new version ALL of the records lead to this error so it has to do something with the data in the DB which means SOME method in the code behaves differently to nulls but I cant find out exactly what the issue is because my app is 30k lines of code</p>
  
  <p>after searching around and trying various solutions, the below 2 are not the solutions to my issue. </p>
  
  <p>forums.asp.net/t/1357862.aspx 
  <a href="http://www.vbforums.com/showthread.php?t=656246" rel="nofollow">http://www.vbforums.com/showthread.php?t=656246</a></p>
  
  <p>I want to mention that I am already having a difficult time dealing with this application because it was written by other programmers that are now long gone leaving behind non-documented or commented spaghetti code.</p>
  
  <p>I did not code this but other programmers from past have put Response.Write in code:</p>
  
  <pre><code>   private void MessageBox(string msg)
      {
          if (!string.IsNullOrEmpty(msg))
          {
              Global.tmpmsg = msg;
              msg = null;
          }
          Response.Write("&lt;script type=\"text/javascript\" language=\"javascript\"&gt;");
          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("&lt;/script&gt;");
  
      }
  </code></pre>
  
  <p>This one is in another method:</p>
  
  <pre><code>        Response.Write("&lt;script type=\"text/javascript\" language=\"javascript\"&gt;");
          Response.Write("alert('No search resuls were found');");
          Response.Write("&lt;/script&gt;"); 
  </code></pre>
  
  <p>Or This:</p>
  
  <pre><code>if (!string.IsNullOrEmpty(msg))
  {
      Global.tmpmsg = msg;
      Response.Write("&lt;script type=\"text/javascript\" language=\"javascript\"&gt;");
      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("&lt;/script&gt;");
  }
  </code></pre>
  
  <p>After Jrummel`s comment I added this to code and then nothing at all happened.</p>
  
  <pre><code>private void MessageBox(string msg)
  {/*
      if (!string.IsNullOrEmpty(msg))
      {
          Global.tmpmsg = msg;
          msg = null;
      }
      Response.Write("&lt;script type=\"text/javascript\" language=\"javascript\"&gt;");
      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("&lt;/script&gt;");
      */
  // 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 = "&lt;script type=\"text/javascript\" language=\"javascript\"&gt;" + " " + "window.open('ErrorPage.aspx?msg=" + "','PopUp','screenX=0,screenY=0,width=700,height=340,resizable=1,status=no,scrollbars=yes,toolbars=no');" + " " + "&lt;/script&gt;";
    cs.RegisterStartupScript(cstype, csname1, cstext1, false);
  }
  
  
  
  }
  </code></pre>