How To Validate Visual InterDev Design-Time Controls with Client and Server Scripting Platforms (270714)



The information in this article applies to:

  • Microsoft Visual InterDev 6.0

This article was previously published under Q270714

SUMMARY

This article describes how to validate a Visual InterDev Design-Time Control (DTC) with both client-side and server-side DTC scripting platforms.

MORE INFORMATION

Server-side DTC

In order to validate a server-side DTC from client-side code, you need to use the thisPage_onbeforeserverevent method. This method allows you to validate your server-side DTCs with regular client-side JavaScript. To do this, perform the following steps:
  1. Create a new Visual InterDev project, and add a Data Connection.
  2. Add an Active Server Pages (ASP) page to the project.
  3. Drag a Recordset DTC from the toolbox, and place it in the <BODY> section of the new ASP page. If you are prompted to enable the Scripting Object Model, click Yes. Set the following properties for the Recordset:
    1. Set Connection to the name of the Data Connection that you created in step 1.
    2. Set Database Object to Tables.
    3. Set Object Name to the name of a table in your database.
  4. Drag a Textbox DTC from the toolbox, and place it in the <BODY> section of your ASP page after the Recordset DTC. Right-click the Textbox DTC, and select Properties. In the resultant dialog box, set the following properties:

    1. Set Recordset to the Recordset DTC that you created in step 3.
    2. Set Field to a valid field name in your database.
    Click OK.
  5. Drag a Button DTC from the toolbox, and place it in the <BODY> section of your ASP page after the Recordset DTC. Right-click the Button DTC, and select Properties. In the resultant dialog box, set the following properties:

    1. Set Name to btnUpdate.
    2. Set Caption to Update.
    Click OK.
  6. Paste the following server-side ASP code in the heading section of your page:
    <%
    Sub btnUpdate_onclick()
    Recordset1.updateRecord
    End Sub
    %>
    					
  7. Paste the following client-side ASP code in the heading section of your page:
    <SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
    <!--
    //This function is used to validate data on the 
    //client before it is submitted to the server.
    function thisPage_onbeforeserverevent( obj, event ){
    	if (obj=="btnUpdate")
    	{
    		if(event=="onclick")
    		{
    			if(document.thisForm.Textbox1.value == "Test Value")
    			{
    				// Validation Code
    				alert("Will Update");
    			}
    			else
    			{
    				alert("This is not a valid value!");<BR/>
                                    // Cancel the update.
    				thisPage.cancelEvent = true;
    			}
    			
    		} 
    	}
    	
    }
    //-->
    </SCRIPT>
    					
  8. You can now change and update the value in the textbox. When you click the Update button, the validation script tests if the value is "Test Value." If it is, the data is updated. Otherwise, a message box warns that the value is not correct, and the update event is cancelled.

Client-side DTC

NOTE: Client-scripted DTCs use Dynamic Hypertext Markup Language (DHTML) and Remote Data Services (RDS), which are not supported in Netscape browsers.

In order to validate a client-side DTC, your validation code must consist only of client-side code. To do this, perform the following steps:
  1. Create a new Visual InterDev project, and add a Data Connection.
  2. Add an Active Server Pages (ASP) or HTML page to the project.
  3. In the HTML Source editor, make sure that you are on the Source tab. Right-click between the <BODY> and </BODY> tags, and select Properties. In the resultant Properties dialog box, make sure that the DTC scripting platform is set to Client (IE 4.0 DHTML), and then click OK.
  4. Drag a Recordset DTC from the toolbox, and place it in the <BODY> section of the new page. If you are prompted to enable the Scripting Object Model, click Yes. Set the following properties for the Recordset:
    1. Set Connection to the name of the Data Connection that you created in step 1.
    2. Set Database Object to Tables.
    3. Set Object Name to the name of a table in your database.
  5. Drag a Textbox DTC from the toolbox, and place it in the <BODY> section of your ASP page after the Recordset DTC. Right-click the Textbox DTC, and click Properties. In the resultant dialog box, set the following properties:

    1. Set Recordset to the Recordset DTC that you created in step 4.
    2. Set Field to a valid field name in your database.
    Click OK.
  6. Drag a Button DTC from the toolbox, and place it in the <BODY> section of your ASP page after the Recordset DTC. Right-click the Button DTC, and select Properties. In the resultant dialog box, set the following properties:

    1. Set Name to btnUpdate.
    2. Set Caption to Update.
    Click OK.
  7. Paste the following client-side JavaScript code in the heading section of your page:
    <SCRIPT LANGUAGE=javascript>
    <!--
    
    function btnUpdate_onclick(){
      if(document.thisForm.Textbox1.value == "Test Value")
      {
         // Validation Code
         alert("Will Update");
         document.thisForm.action = "DTCvalidationClient.asp";
         document.thisForm.submit();
      }
      else
      {
         alert("This is not a valid value!");
      }
    }
    //-->
    </SCRIPT>
    					
  8. You can now change and update the value in the textbox. When you click the Update button, the validation script tests if the value is "Test Value." If it is, the data is updated. Otherwise, a message box warns that the value is not correct, and the update event is cancelled.

REFERENCES

For additional information on the onbeforeserverevent event, see the following page on the Microsoft Developer Network (MSDN):

Modification Type:MajorLast Reviewed:5/2/2006
Keywords:kbCtrl kbhowto kbScript KB270714