Microsoft KB Archive/232218

= How To Enable the SOM on an ASP Page That Has a  Tag =

Article ID: 232218

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft Visual InterDev 6.0 Standard Edition

-



This article was previously published under Q232218



SUMMARY
This article assumes that you are familiar with HTML, Active Server Pages (ASP), and the Scripting Object Model (SOM). When you have a FORM tag on your ASP, and you enable the SOM either manually or by adding server-side Design-Time Controls (DTC) to the ASP, the FORM might no longer be functioning properly and errors might occur. This article describes the issues relating to ASPs with nested FORM tags and offers procedures to work around them.



Sample Scenario:
If you have an ASP with the following FORM:       in the window_onload client event handler, (use the Script Outline of Visual InterDev's Interactive Development Environment (IDE) to go to the window_onload script block), you have the following code to initialize the textbox named text1: function window_onload { Form1.text1.value =('test'); }

Undesired Behavior
When you enable SOM (either manually or after dragging and dropping any DTCs to the ASP), and then view the ASP in a Web browser after enabling the SOM, the following errors or behaviors can occur:  An error message indicating:

Form1 is undefined

When using the SUBMIT button to submit the ASP, the ASP is not being submitted to the action handler, in this case, "action.asp:" When using the SUBMIT button to submit the ASP, the ASP is not being submitted to the action handler, in this case, "action.asp:"

This occurs because when you enable the SOM, an additional FORM tag is added to the ASP as shown below: <FORM name=thisForm METHOD=post> This generally results in errors in two areas:
 * errors when referencing HTML intrinsic controls and ActiveX controls and,
 * errors when submitting the ASP.

Workaround
To work around this problem, follow the steps below:   Remove the original FORM tag, in this case, the following two lines: <FORM id=form1 name=form1 action="action.asp"> ... </FORM> </li>  To ensure the controls (ActiveX, HTML intrinsic, and DTCs) on the ASP are referenced properly, change the window_onload event handler to the following, specifying 'thisForm' instead of the FORM name: function window_onload { thisForm.text1.value =('test'); }                    </li>  The following line is added to the ASP by enabling the SOM: <FORM name=thisForm METHOD=post> Because the above line is not editable from within Visual InterDev, you need to specify the FORM action handler in a separate function. In this case, you can modify the original ASP to manually submit the page as shown below: <FORM name=thisForm METHOD=post> <BODY LANGUAGE=javascript onload="return window_onload"> <INPUT type="text" id=text1 name=text1> <INPUT type="submit" value="Submit" id=submit1 name=submit1 onclick="manualsubmit"> </BODY> </FORM> The function "manualsubmit" is added to submit the form to the correct ASP, in this case, "action.asp:" <SCRIPT LANGUAGE="JAVAScript"> function manualsubmit {   thisForm.action='action.asp'; } </SCRIPT> </li></ol>

<div class="references_section">