This topic is locked
[SOLVED]

virtual field (non database field) on an add page

4/13/2022 10:06:13 PM
ASPRunner.NET Tips and tricks
R
Rajesh author

HI,
In add page of a table x, I am autopopulating few fileds from another reference table y.
But there are some fields in table y which don't exist in table x, and I want to just display those fields on the add page.
These fileds obviously will not and can not be inserted into table x because they don't exist.
Is there a way to do this?

Thanks,
Rajesh

Pete K 4/14/2022

Hi Rajesh,

This is also a common scenario for me and the only way I've been able to manage is to insert a code snippet on the page and write code to display the data from the other table. You can of course add "fake" fields to the page by modifying the table query, but in that case you are faced with the add and edit pages attempting to modify the fake fields, which naturally throws an exception. I have long wished for a feature that would allow us to mark a field as "do not update" so the add/edit update pages display them but ignore them when doing the update. That would help in cases like this.

Hope this helps.

—Pete

R
Rajesh author 4/14/2022

Hi Pete,

Thank you for your response. I agree, that feature would help a lot.
I am now looking for a code snippet example.

--Rajesh

W
WilliamBDevClub member 5/15/2022

This is easy. I don't use code snippits for this as that requires another query. I add a dummy field as explained above.

You just need to unset the value that you do not want added/updated. (As stated, they don't exist in the database.)

On add page use Before added event and on an edit page use Before updated event.

unset($values["Your_Field"]);

Do this to every field you want to ignore.

jadachDevClub member 5/15/2022

unset will not work with aspr.net

I have had success using

var ctrl = Runner.getControl(pageid, 'Make');
ctrl.setDisabled();

I can auto-populate "fake" fields, display them and not submit them.

Sergey Kornilov admin 5/15/2022

Yes, it can be done.

  1. Add a calculated field to your SQL query

select ...
'' as dummy
from tablename
  1. Make sure it only appears on the Add page


  2. "Unset" in in BeforeAdd event.



values.Remove("dummy");

R
Rajesh author 6/8/2022

Thank you everyone.
I was able to create a view joining the 2 tables x and y and using a database trigger to selectively add fields.

-Rajesh