This topic is locked

Conditional formatting on edit page

4/10/2019 12:45:27 PM
ASPRunner.NET General questions
T
Tim author

Hi all,
I am trying to do some conditional formatting based on this from the help file:
https://xlinesoft.com/asprunnernet/docs/change_cell_background_color.htm
I need to do this on an edit page and only if 2 fields don't match. So, in the "Process record values" event I have this code:



if (values["AccountNumber"].ToString() != values["NewAccountNumber"].ToString() )

{

record["NewAccountNumber_css"] = "background: red;";

}


When I build the project I get the error "The name 'record' does not exist in the current context". So I gather this code from the help file isn't meant for this event. So how do I change the formatting on an edit page based on the condition of 2 fields not matching? And I don't need this done dynamically (like when a value changes on the page), I just need it when the page loads.
Thanks,

Tim

admin 4/10/2019

"After Record Processed" and "Process record values" are two different events. First one designed to work on List/Print pages while second runs on Add/Edit/View pages and serves a totally different purpose.
Your best option to make changes like this is to use Javascript OnLoad event. I'm not 100% sure though what exactly you want to change as there is no table cell on the Edit page.

T
Tim author 4/11/2019

Yes, I realized all of this shortly after I posted. And I will change the formatting on the font instead of a cell.
Here is what I'm thinking in the Javascript onload event:



var ctrlBN = Runner.getControl(pageid,'BusinessName');

var ctrlNBN = Runner.getControl(pageid,'NewBusinessName');
if (ctrlBN != ctrlNBN) {

ctrlNBN.addStyle(color:red);

}


Unfortunately there are a lot of fields on this page, so there will be much typing. All corresponding fields are named the same with "New" added in front. I wonder if there's a way to loop through all fields so I don't have to type each one... ?
Thanks,

Tim

admin 4/12/2019

To get all the controls of the table, you need to pass only the table name as the argument:

var ctrlArr = Runner.controls.ControlManager.getAt(tableName);


More info (see first example):

https://xlinesoft.com/phprunner/docs/ctrl_addvalidation.htm