I am working on a page in classic asp with vbscript for server side processing. On page 1, named criteriaregionbkp.asp, there is a dropdown having list of employees. User selects employees from this dropdown and clicks the add button. Upon clicking the Add button, I need to add Employee Number, Name and Region in an HMTL table on the same page. So for example, when the user selects Name1, HTML table will show:
EmployeeNumber1 Name1 Region1
Now when the user selects Name2, HTML table on the same page will show:
EmployeeNumber1 Name1 Region1
EmployeeNumber2 Name2 Region2
When the user is done adding employees in the table, there is a Submit button at the end of the table. User will click submit, criteriaregionbkp.asp will submit and next page as per action attribute will be inserttoxs.asp where the values entered in HTML table on criteriaregionbkp.asp will be read and inserted in an access file.
The issue that I am facing is that I need to retain values of HTML table, when the user clicks Add after the first time. For example, when the user selects Name2 and clicks Add, page posts back to criteriaregionbkp.asp and I need to retain previous values EmployeeNumber1 Name1 Region1. I tried to accomplish this by assigning recordset to session but I am getting an error in this:
<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" HEIGHT="53">
<TR>
<td width=20%> </td>
<TD width=50%>
<DIV ALIGN="CENTER"><INPUT TYPE="button" NAME="Submit1" VALUE="Add" style="width: 80px;" onClick="<%="submitFunction(1," & Request.QueryString("cntr")+1 & ")"%>"></DIV>
</TD>
<td width=30%> </td>
</TR>
</TABLE>
Request.QueryString("cntr") will be nil when page first loads. Upon subsequent postbacks, Request.QueryString("cntr") will become 1, then 2 and so on…
When I run this page and select first employee name, it appears in the HTML table correctly. When I select second employee name and click Add, I get the following error:
Operation is not allowed when the object is closed.
This error occurs on this line:
EmployeeNumber1 Name1 Region1
Now when the user selects Name2, HTML table on the same page will show:
EmployeeNumber1 Name1 Region1
EmployeeNumber2 Name2 Region2
When the user is done adding employees in the table, there is a Submit button at the end of the table. User will click submit, criteriaregionbkp.asp will submit and next page as per action attribute will be inserttoxs.asp where the values entered in HTML table on criteriaregionbkp.asp will be read and inserted in an access file.
The issue that I am facing is that I need to retain values of HTML table, when the user clicks Add after the first time. For example, when the user selects Name2 and clicks Add, page posts back to criteriaregionbkp.asp and I need to retain previous values EmployeeNumber1 Name1 Region1. I tried to accomplish this by assigning recordset to session but I am getting an error in this:
Code:
<TABLE width="100%" border="1" cellspacing="0" cellpadding="0">
<TR>
<TD width=20%><b><font color="#660000">Employee Number</font></b></TD>
<TD width=50%><b><font color="#660000">Name</font></b></TD>
<TD width=30%><b><font color="#660000">Region</font><b></TD>
</TR>
<%call fillgrid()%>
</TABLE>
<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" HEIGHT="53">
<TR>
<td width=20%> </td>
<TD width=50%>
<DIV ALIGN="CENTER"><INPUT TYPE="button" NAME="Submit1" VALUE="Add" style="width: 80px;" onClick="<%="submitFunction(1," & Request.QueryString("cntr")+1 & ")"%>"></DIV>
</TD>
<td width=30%> </td>
</TR>
</TABLE>
Code:
sub fillgrid()
dim sql
Const adInteger = 3
Const adChar = 129
if Request.QueryString("cntr")<>"" then
call connect()
set rs2=server.CreateObject("ADODB.Recordset")
set rs3=server.CreateObject("ADODB.Recordset")
set rs4=server.CreateObject("ADODB.Recordset")
with rs3.Fields
.Append "Employee", adInteger
.Append "Name", adChar, 250
.Append "Region", adChar, 100
end with
rs3.CursorType=3
rs3.LockType=3
rs3.Open
sql="select firstname || ' ' || middlename || ' ' || lastname as empname,region.name from "
sql=sql & session("bookcode") & ".empprofile," & session("bookcode") & ".units," & session("bookcode")
sql=sql & ".region where empprofile.unitcode=units.code and units.regioncode=region.code and "
sql=sql & "empcode=" & Request.Form("empname")
rs2.Open sql,cn
rs3.AddNew
rs3.Fields("Employee").Value=Request.Form("empname")
rs3.Fields("Name").Value=rs2.Fields("empname")
rs3.Fields("Region").Value=rs2.Fields("name")
rs3.Update
if Request.QueryString("cntr")>1 then
set rs4 = Session("myrs")
do while not rs4.EOF
rs3.AddNew
rs3.Fields("Employee").Value=rs4.Fields("Employee")
rs3.Fields("Name").Value=rs4.Fields("Name")
rs3.Fields("Region").Value=rs4.Fields("Region")
rs3.Update
rs4.MoveNext
loop
end if
rs2.Close
do while not rs3.EOF
Response.Write "<TR><TD>" & rs3.Fields("Employee") & "</TD><TD>" & rs3.Fields("Name") & "</TD><TD>" & rs3.Fields("Region") & "</TD></TR>"
rs3.MoveNext
loop
set Session("myrs") = rs3
rs3.Close
end if
end sub
Request.QueryString("cntr") will be nil when page first loads. Upon subsequent postbacks, Request.QueryString("cntr") will become 1, then 2 and so on…
When I run this page and select first employee name, it appears in the HTML table correctly. When I select second employee name and click Add, I get the following error:
Operation is not allowed when the object is closed.
This error occurs on this line:
Code:
do while not rs4.EOF