I’m working on a .Net web application project that run on IIS 7 with Application Pool on .Net Framework 2.0 and it’s working properly. After I upgrade the application pool to .Net Framework 4.0 version, all my form elements assigning or retrieving the value are stopped working. The form is generated dynamically in the code behind so I’m not sure how the >form< tag is built.
On .Net Framework 2.0, the form is rendered as below:
[text]<form name="frmProduct" action="Products.aspx" id="frmProduct">[/text]And below is the way I use to assign the value of an element named “txtAmount”:
document.frmProduct.txtAmount.value = 10; |
It’s working properly.
But on .Net Framework 4.0, the form doesn’t have the “name” property
<form action="Products.aspx" id="frmProduct"> |
When I test on Firefox, it shows error message in Error Console: “document.frmProduct is undefined” and it passes the script line: “document.frmProduct.txtAmount.value = 10;”.
To fix the form element becomes undefined issue, I have to use another way of assigning the value as below:
document.getElementById('txtAmount').value = 10; |
And it’s working again as dream 🙂
The way to fix it is really simple with experience Developer but I have to spend 2-3 hours to work it out as the form generation is in the code behind and all source codes have been complied to DLL already.
Anyway, It’s done now. Happy programming & debugging.