This topic is locked

Auto Populating Fields on an 'Add Page' Using Field Event

11/7/2019 1:30:32 AM
ASPRunner.NET General questions
I
IanT author

Hi, I'm new to ASPRunner.net

I've looked through the forum and found a few threads that have similar questions to this, but I cannot seem to find anything that does exactly what I want.

I'm using the latest version of ASPRunner.net
I have an 'add' form adding records to a table and I want to auto populate other fields on the add page when the customer number is entered, before the record is saved.
I've successfully used the 'Autofill' function when setting the customer number as lookup field, however this is proving to be an annoyance to the users as the lookup table has over 400,000 records in it and using the drop-down lookup makes it slower to add a value.
My preference is to have the user enter the customer number, then using a 'Change' field event, have the other fields on the add page auto populated.
I understand I need to create three bits of code (client before, server and client after)... but just cannot seem to get it to work.
The field on the add page is 'CNSHAN' which is the account number
I then want to fetch the account name and branch from another table in the same database. The table is 'F0101' and the fields are 'ABALPH' and 'ABMCU' which is the account name and branch respectively.

The account number on the 'F0101' table is ABAN8, so the data to be fetched would be 'Select ABALPH, ABMCU from F0101 where ABAN8=CNSHAN'

ABAN8 is the primary key for the F0101 table, so only one record would ever be returned.
I then want to auto populate the ABALPH and ILMCU fields on the same add page and allow the user to edit these values if necessary.

I would like the account name to display "Invalid Account Number" if the account number entered is not present in the F0101 table.

It would be awesome if I could disable the 'Save' button if the "Invalid Account Number" message is displayed.
Apologies if this is already covered somewhere

Cheers

Ian

admin 11/7/2019

Start with this article, it provides two examples of how to use field events:

https://xlinesoft.com/asprunnernet/docs/field_events.htm
Example 1 shows how to perform a lookup.
Start with this and ask more specific questions so we can assist.

jadachDevClub member 11/8/2019

Another option is to use the lookup wizard using Edit box with Ajax popup. This is the best way to deal with very large data sets in the lookup table.
Mark that field as required. Then use the Autofill feature to populate your other fields.

I
IanT author 11/15/2019



Start with this article, it provides two examples of how to use field events:

https://xlinesoft.com/asprunnernet/docs/field_events.htm
Example 1 shows how to perform a lookup.
Start with this and ask more specific questions so we can assist.


Thanks Sergey, I'm still having trouble thou.

On my account number field I have created a field event
'Client Before' is:

params["val"] = this.getValue();
'Server' is:

result["ABALPH"] = tDAL.DBLookup("Select ABALPH, ABMCU from PRODDTA.F0101 where ABAN8=parameters["val"]);
'Client After' is:

ctrlABALPH.setValue(result["ABALPH"]);
When the project is compiling it fails with the following error:

include\CommonEvents.cs(56,102): error CS1010: Newline in constant [C:\CH2ASP\COOLPAC\output\COOLPACEventsCS.csproj]
I'm guessing the 'Server' code is wrong as I need to specify an array as I'm selecting two fields from the F0101 table.
I would also need to specify that I want to populate the ABMCU from the SQL query into the ILMCU on the add page.
Sorry... new to the .net version, I'm good with SQL code, but this is confusing me.

I
IanT author 11/15/2019



Another option is to use the lookup wizard using Edit box with Ajax popup. This is the best way to deal with very large data sets in the lookup table.
Mark that field as required. Then use the Autofill feature to populate your other fields.


Thanks Jerry, I will give this a try. This will help.
I would still like to get the field event working thou as I have some more complex stuff I want to resolve using the field event mothod

admin 11/17/2019

Ian,
you are mixing strings with variables in your Server code, it simply won't work.
If you take another look at the article I posted you can see the proper way to build a SQL query:

result["catName"] = tDAL.DBLookup("select CategoryName from categories where CategoryID='" + parameters["val"].ToString() + "'");