CodeCharge Studio All ASP PHP Perl ColdFusion Java C#.NET

RemoteCustomCode

Description

The RemoteCustomCode feature is used to add client-side code to initiate a request for information from the server, and add server-side code to service the request.  e.g. a simple database request.

Like the ClientCustomCode feature, CodeCharge Studio adds code stubs which you must find in the source in order to add your code.  e.g. if the RemoteCustomCode feature is named RemoteCustomCode1, then you search the HTML source for the code stub like:

//RemoteCustomCode1 Parameters @77-C04C081F
// -------------------------
// Add request parameters here.
// -------------------------
//End RemoteCustomCode1 Parameters
//RemoteCustomCode1 Code @3-2A29BDB7
// -------------------------
// Write your own code here.
// -------------------------
//End RemoteCustomCode1 Code

and the server code for:
//RemoteCustomCode1 Displaying @72-2A29BDB7
// -------------------------
// Write your own code here.
// -------------------------
//End RemoteCustomCode1 Displaying

Supported Components

All forms and controls

Properties

Property Description
Enabled Specifies whether the feature is active.
Start event Client event or condition that starts the Custom Code execution.
Asynchronous Determines whether XMLHttpRequest is used asynchronously or not.

Sample Implementation

HTML

//RemoteCustomCode1 Parameters @77-C04C081F

 method = "post";
 parameters["article_id"] = "1";	

//End RemoteCustomCode1 Parameters
//RemoteCustomCode1 Code @3-2A29BDB7

 alert (transport.responseText);

//End RemoteCustomCode1 Code

Server code (ASP)

//RemoteCustomCode1 Displaying @72-2A29BDB7

 Dim DB
 Dim SQL
 Dim RecordSet

 Set DB = New clsDBInternetDB
 DB.Open
 SQL = "SELECT article_title FROM articles WHERE article_id=" & DB.ToSQL(CCGetFromPost("article_id", ""), ccsInteger)
 Set RecordSet = DB.Execute(SQL)
 Response.Write("Article title: " & CCGetValue(RecordSet, "article_title"))
 DB.Close

//End RemoteCustomCode1 Displaying

Server code (PHP)

//RemoteCustomCode1 Displaying @72-2A29BDB7

 $db = new clsDBInternetDB();
 $SQL = "SELECT article_title FROM articles WHERE article_id=" . $db->ToSQL(CCGetFromPost("article_id"), ccsInteger);
 $db->query($SQL); 
 if( $db->next_record() ) echo "Article title: " . $db->f("article_title");  
 $db->close();
 
//End RemoteCustomCode1 Displaying  

Server code (Perl)

//RemoteCustomCode1 Displaying @72-2A29BDB7

 $db = clsDBInternetDB->new();
 $SQL = "SELECT article_title FROM articles WHERE article_id=" . $db->ToSQL(CCGetFromPost("article_id"), ccsInteger);
 $db->query($SQL); 
 if( $db->next_record() ) echo "Article title: " . $db->f("article_title");  
 $db->close();
 
//End RemoteCustomCode1 Displaying  

Server code (ColdFusion)

<---RemoteCustomCode1 Displaying @72-2A29BDB7--->

 <CFMODULE Template="CCToSQL.cfm" Value="#Form.article_id#" Type="#ccsInteger#" outputVar="fldArticleId" Mode="SQL">
 <CFSET strSQL="SELECT article_title FROM articles WHERE article_id=" & fldArticleId>
 <CFMODULE Template="CCOpenRS.cfm" strName="ArticleId" sql="#strSQL#">
 Article title: <cfoutput>#queryArticleId.article_title#</cfoutput>

<---End RemoteCustomCode1 Displaying--->

Server code (Java)

//RemoteCustomCode Displaying @8-CF03A764
public void remoteCustomCodeDisplaying( HttpServletRequest request, HttpServletResponse response, ServletContext context ) {
   try {
      JDBCConnection conn = JDBCConnectionFactory.getJDBCConnection("InternetDB");
      String SQL = "SELECT article_title FROM articles WHERE article_id=" + conn.toSql(request.getParameter("article_id"), JDBCConnection.INTEGER);
      DbRow row = conn.getOneRow(SQL);
      response.getWriter().print("Article title: " + Utils.convertToString(row.get("article_title")));   
      conn.closeConnection();
   } catch (Exception e) {
	  // do something meaningful here
      System.out.println("Exception: " + e.toString());
   } 
}
//End RemoteCustomCode Displaying

Server code (C# InMotion)

   
//RemoteCustomCode RemoteCustomCode1 Displaying @4-2A29BDB7
  try {
     Connection conn = InMotion.Configuration.AppConfig.GetConnection("InternetDB");
     DataCommand command = (DataCommand)conn.CreateCommand();
     command.MTCommandType = MTCommandType.Table;
     command.CommandText = "SELECT article_title FROM articles WHERE article_id = {article_id}";
     command.Parameters.Clear();
     command.Parameters.Add(new InMotion.Data.SqlParameter("article_id", DataType.Integer));
     command.Parameters["article_id"].Value = parameters["article_id"].ToString();
     result = "Article title: " + command.ExecuteScalar().ToString();
  } catch (Exception e) {
     // do something meaningful here
     result = "Exception: " + e.ToString();
  }
//End RemoteCustomCode RemoteCustomCode1 Displaying

See also


On-line, printable versions and updates