How To Use the Event Keypress on Visual InterDev 6.0 Design-Time Controls (264019)



The information in this article applies to:

  • Microsoft Visual InterDev 6.0

This article was previously published under Q264019

SUMMARY

Visual InterDev 6.0 Design-Time Controls (DTCs) do not expose all of a control's events. This is because the DTCs are most commonly scripted on the server, and exposing all of the events would decrease performance. The decrease in performance would be caused by additional round-trips to the server for the additional events. However, you can use the "advise" method to expose additional properties and events.

MORE INFORMATION

The example in this section will show you how to use the advise method to create an "onkeypress" event. This example uses two Textbox DTCs. When the page is complete and is viewed in the Web browser, every number between 0 and 9 that is typed into the first Textbox control will appear in the second Textbox control.

Create the HTML page and Add DTCs

  1. Add an HTML page to your project. Switch to the Source tab within the Visual InterDev HTML Source Editor.
  2. From the Design-Time Control section of the Toolbox, drag two Textbox DTCs and place them into the <BODY> section of the HTML page.
  3. Add the following code to your HTML page before the closing </HEAD> tag:

    Microsoft Visual Basic Script (VBScript) Version:
    <SCRIPT LANGUAGE="VBScript">
    
    Dim objAdviseTextbox1 
    
    Function window_onload()
       objAdviseTextbox1 = Textbox1.advise("onkeypress", "Text1_KeyPress()")
    End function
    
    Function Text1_KeyPress()
       strChar = Chr(window.event.keycode)
       If strChar >= "0" and strChar <= "9" then
          Textbox2.value = Textbox2.value & strChar
       End if
    End function
    
    </SCRIPT>
    						

    -or-

    JavaScript Version:
    <SCRIPT LANGUAGE="JavaScript" for="window" event="onload">
    
    objAdviseTextbox1 = Textbox1.advise("onkeypress", "Text1_KeyPress()");
    
    </SCRIPT>
    
    <SCRIPT LANGUAGE="JavaScript">
    
    function Text1_KeyPress(){
       strChar = String.fromCharCode(window.event.keyCode);
       if (strChar>="0" && strChar<="9"){
          Textbox2.value = Textbox2.value + strChar;
          }
       }
    
    </SCRIPT>
    					
NOTE: When you no longer want to manipulate the event, you can cancel it by calling the object's unadvise method. This method needs the object that is returned by the advise method and the name of the event. The following shows an example of how to call unadvise:
Textbox1.unadvise("onkeypress", objAdviseTextbox1)
				

Modification Type:MinorLast Reviewed:7/13/2004
Keywords:kbCtrl kbhowto kbScript KB264019