Microsoft KB Archive/264019

= How To Use the Event Keypress on Visual InterDev 6.0 Design-Time Controls =

Article ID: 264019

Article Last Modified on 7/13/2004

-

APPLIES TO


 * Microsoft Visual InterDev 6.0 Standard Edition

-



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 &quot;advise&quot; 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 &quot;onkeypress&quot; 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
 Add an HTML page to your project. Switch to the Source tab within the Visual InterDev HTML Source Editor. From the Design-Time Control section of the Toolbox, drag two Textbox DTCs and place them into the  section of the HTML page.  Add the following code to your HTML page before the closing  tag:

Microsoft Visual Basic Script (VBScript) Version:



Dim objAdviseTextbox1

Function window_onload objAdviseTextbox1 = Textbox1.advise(&quot;onkeypress&quot;, &quot;Text1_KeyPress&quot;) End function

Function Text1_KeyPress strChar = Chr(window.event.keycode) If strChar >= &quot;0&quot; and strChar <= &quot;9&quot; then Textbox2.value = Textbox2.value & strChar End if End function



-or-

JavaScript Version: 

objAdviseTextbox1 = Textbox1.advise(&quot;onkeypress&quot;, &quot;Text1_KeyPress&quot;);





function Text1_KeyPress{ strChar = String.fromCharCode(window.event.keyCode); if (strChar>=&quot;0&quot; && strChar<=&quot;9&quot;){ Textbox2.value = Textbox2.value + strChar; }  }

</SCRIPT> </li></ol>

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(&quot;onkeypress&quot;, objAdviseTextbox1)

<div class="references_section">