HOWTO: Display Error Messages From the Server When Remote Scripting

ID: Q238284


The information in this article applies to:
  • Microsoft Internet Information Server version 4.0


SUMMARY

If you have an HTML page that uses Remote Scripting, and you encounter an error that occurred on the server, a dialog box appears with the following message:

Remote Scripting Error
REMOTE SCRIPTING ERROR: Page Invoked does not support Remote Scripting.
Unfortunately, this error message does not provide any useful information in resolving the issue. This article shows how you can use the data and status properties of the object returned to display the error returned from the server.

The status property of the Remote Scripting object will tell us whether or not we encountered an error (0 = no error) and the data property will return the contents of that error.

One more thing you need to consider is that server errors from Internet Information Server (IIS) are formatted as HTML. As a result, the data property contains the HTML returned instead of formatted text. This can make the error text difficult to read. This article also shows how to place the content of the data property into a browser window (using window.open and document.write) so that the error results display formatted.


MORE INFORMATION

To create the sample, follow these steps: IMPORTANT: These steps assume that you have remote scripting installed in the _ScriptLibrary subfolder of your Web.

  1. Create an Active server page in your Web named "sample_server.asp" and include the following code:
    
    <%@ LANGUAGE=VBSCRIPT %>
    <!--#include file="_ScriptLibrary/rs.asp"-->
    <% RSDispatch %>
    <SCRIPT Language=JavaScript RUNAT=SERVER>
    	function Description()
    	{ 
    		this.myFunction = myFunction;
    	}
    	public_description = new Description();
    
    
    	function myFunction()
    	{
    	    ForceError();   //This will force a server-side error
    	}
    
    </SCRIPT> 


  2. Create an HTML page in your Web named "sample_client.htm" with the following code:
    
    
    <HTML>
    <BODY>
    <SCRIPT Language="JavaScript" src="_ScriptLibrary/rs.htm"></SCRIPT>
    <h2>Sample Remote Scripting Client</h2>
    
    <SCRIPT LANGUAGE="javascript">
    	RSEnableRemoteScripting();
    
    	var serverURL = "sample_server.asp";
    	function myTest()
    	{
    		var RSObj = RSExecute(serverURL, "myFunction");
    		
    		if (RSObj.status != 0) { WriteError(RSObj.data); }
    	} 
    
    	function WriteError(strHTML) {
    	  var w = window.open("","error_window","width=500,height=300,toolbar=no,location=no,directories=no,status=no,menubar=no")
    	  w.document.write("<HTML>");
    	  w.document.write("<BODY>");
    	  w.document.write("<CENTER>");
    	  w.document.write("<H2>Remote Scripting Call Returned the following:</H2>");
    	  w.document.write("<TABLE border=1 cellpadding=10 bgcolor=#dddddd><TR><TD>");
    	  w.document.write(strHTML)
    	  w.document.write("</TD></TR></TABLE>");
    	  w.document.write("<FORM><INPUT type=button value=\" OK \" onclick=self.close()></FORM>");
    	  w.document.write("</CENTER>");
    	  w.document.write("</BODY>");
    	  w.document.write("</HTML>");
    	}
    </SCRIPT>
    <form>
    <input type=button name=rstest value=" Go " onclick="myTest()">
    </form>
    </BODY>
    </HTML> 


  3. Open "sample_client.htm" in your browser (using HTTP://) and click Go. The error occurs and a new window will be written that shows the formatted HTML.



REFERENCES

Additional query words:

Keywords : kbASP kbScript kbGrpASP kbDSupport kbiis400
Version : winnt:4.0
Platform : winnt
Issue type : kbhowto


Last Reviewed: September 22, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.