PRB: Forms 2.0 CommandButton Fires Click Event When Disabled

ID: Q188766


The information in this article applies to:


SYMPTOMS

The Forms 2.0 CommandButton control can be disabled by setting the value of its Enabled property to false.

When this control is placed inside a table cell on a Web page, the Click event for the control can be fired even though the control is disabled.

The Click event for the control cannot be fired if the control is disabled and placed outside of a table.


CAUSE

The Forms 2.0 controls were designed for use with earlier versions of Microsoft Internet Explorer.


RESOLUTION

  1. The recommended resolution for this problem is to use the intrinsic button control by specifying the following HTML:
    
    <INPUT TYPE=BUTTON ID=MyButton VALUE="My Button"> 
    The following script disables the control when the page is displayed:
    
    <SCRIPT LANGUAGE=VBScript FOR=Window EVENT=onload>
    <!--
       MyButton.disabled = True
    -->
    </SCRIPT> 


  2. If you decide to continue using the Forms 2.0 CommandButton control, you can check the Enabled property of the control when handling the Click event, as demonstrated below:
    
    <SCRIPT LANGUAGE=VBScript FOR=MyButton EVENT=Click>
    <!--
       if ( MyButton.Enabled ) then
          MsgBox "MyButton_Click fired"
       else
          MsgBox "MyButton disabled"
       end if
    -->
    </SCRIPT> 



STATUS

This behavior is by design.


MORE INFORMATION

Steps to Reproduce Behavior

The following HTML demonstrates this problem:

<HTML>
<HEAD>
<SCRIPT LANGUAGE=VBScript FOR=Window EVENT=onload>
<!--
  MyButton.Enabled = False
-->
</SCRIPT>
<SCRIPT LANGUAGE=VBScript FOR=MyButton EVENT=Click>
<!--
  MsgBox "MyButton Click fired"
-->
</SCRIPT>
</HEAD>

<BODY>
<TABLE BORDER=1>
 <TR>
  <TD>
    <OBJECT ID=MyButton
     CLASSID="CLSID:D7053240-CE69-11CD-A777-00DD01143C57">
      <PARAM NAME="Caption" VALUE="My Button">
      <PARAM NAME="Size" VALUE="2540;847">
      <PARAM NAME="ParagraphAlign" VALUE="3">
      <PARAM NAME="FontWeight" VALUE="0">
    </OBJECT>
   </TD>
  </TR>
</TABLE>
</BODY>
</HTML> 


REFERENCES

© Microsoft Corporation 1998, All Rights Reserved.
Contributions by Mark Davis, Microsoft Corporation

Additional query words:


Keywords          : kbcode kbDHTML kbIE400 kbIE401 kbIEObj kbHTMLObj 
Version           : 
Platform          : 
Issue type        : kbprb 

Last Reviewed: May 3, 1999