This topic is locked

AddOnLoad Problem

1/23/2007 3:51:54 AM
ASPRunnerPro General questions
N
NigelEtienne author

I have added the following AddOnLoad event to my add record page. The problem is that even though the code writes the fullname on the page using the Response.Write line, the text field "MyName" is left empty.
Sub AddOnLoad()

'** Display a message on the Web page ****

str = "select from tblEmployees where EmployeeID =" & prepare_for_db("EmployeeID", SESSION(strTableName & "_masterkey1"),"","")

Set rsTemp = server.CreateObject("ADODB.Recordset")

rsTemp.open str, dbConnection

'

'Test of Str code - works on full name is displayed on webpage

Response.Write rsTemp("FullName")
'
'this should populate the MyName field on the page but leaves it blank

Session("MyName") = rsTemp("FullName")*
End Sub
Any help would be gratefully received.

J
Jane 1/23/2007

You also need to use Session("FullName") as default value on the "Edit as" settings dialog on the Visual Editor tab.

N
NigelEtienne author 1/24/2007

You also need to use Session("FullName") as default value on the "Edit as" settings dialog on the Visual Editor tab.



I have added that to the MyName field but it is still blank, do you have any other suggestions?

F
fnqchick 2/4/2007



I have added that to the MyName field but it is still blank, do you have any other suggestions?


Hi There,
I am having the same issues - was this resolved?

C
clig 2/8/2007



I have added that to the MyName field but it is still blank, do you have any other suggestions?


You have listed: Session("MyName") - is this what you have as the default value?

N
NigelEtienne author 2/14/2007



You have listed: Session("MyName") - is this what you have as the default value?


I now have in the event

Session("FullName") = rsTemp("FullName")

and in the default value for textbox MyName

Session("FullName")

The field is populated only after refreshing the screen.

J
Jane 2/15/2007

I see what you're saying. AddOnLoad event executes after ADD page is loaded.

I recommend you to move your code to the ListOnLoad event of the Details table.

F
fnqchick 2/16/2007

I see what you're saying. AddOnLoad event executes after ADD page is loaded.

I recommend you to move your code to the ListOnLoad event of the Details table.


Hi There,
Even with the following code in thelistonload event:
(masterfield) Session("RequestorName") = rsTemp("Requestor") (detailfield)
and
Session("RequestorName") as my detail Requestor field default
I still can't get my fields to autopoplate.
Should the detail fields be readonly or free text?

C
clig 2/18/2007



Hi There,
Even with the following code in thelistonload event:
(masterfield) Session("RequestorName") = rsTemp("Requestor") (detailfield)
and
Session("RequestorName") as my detail Requestor field default
I still can't get my fields to autopoplate.
Should the detail fields be readonly or free text?


TEXT or HIDDEN - Defaults are set to the session variables wanted
This works:
Sub AddOnLoad()

'** Custom code ****

set CN = server.CreateObject("ADODB.Connection")

CN.Open "DSN=dsnname;UID=username;PWD=password"

set rs = Server.CreateObject("ADODB.Recordset")

rs.Open "Select Project, Customer, CustomerNumber, LastCall, simsDate, Notes, [SYS Type] AS SYSTYPE From DIALUP1 Where Project = " & cstr(GetRequestForm("masterkey")), CN

Session("Project") = rs("Project")

Session("Customer") = rs("Customer")

Session("CustomerNumber") = rs("CustomerNumber")

Session("LastCall") = rs("LastCall")

Session("simsDate") = rs("simsDate")

Session("Notes") = rs("Notes")

Session("SYSTYPE") = rs("SYSTYPE")

rs.Close
End Sub
***
Since my fields in this example are not hidden i want to make sure they are correct upon save thus re-assign values:
Function BeforeAdd(dict)
' Parameters:

' dict - Scripting.Dictionary object.

' Each field on the Add form represented as 'Field name'-'Field value' pair
'** Custom code ****

' put your custom code here

dict("Project") = Session("Project")

dict("Customer") = Session("Customer")

dict("CustomerNumber") = Session("CustomerNumber")

dict("LastCall") = Session("LastCall")

dict("simsDate") = Session("simsDate")

dict("ServiceNotes") = Session("Notes")

dict("SYS Type") = Session("SYSTYPE")

dict("Modified") = strUserID & " - " & Now()
BeforeAdd = True
' set BeforeAdd to True if you like to proceed with adding new record

' set it to False in other case
End Function