This topic is locked
[SOLVED]

 Getting record data in a code snippet

3/18/2020 11:03:50 AM
ASPRunner.NET General questions
Pete K author

I've inserted a code snippet into a view page in which I want to use some conditional logic to display a field value along with some other text and formatting. According to the help topic (https://xlinesoft.com/asprunnernet/docs/insert_code_snippet.htm), I should be able to access field values using pageObject:



XVar record = pageObject.getCurrentRecord();

MVCFunctions.EchoToOutput(record["Make"]);


I used similar code for my snippet. However, the compiler throws the following error on the line referencing pageObject.getCurrentRecord():

include\CommonEvents.cs(341,15): error CS0103: The name 'pageObject' does not exist in the current context


Is the help article incorrect or did I miss something?

Pete K author 3/18/2020

Okay, so I solved the issue by getting the editid1 post value and looking up the record with a query. The next wall I hit was using:

MVCFunctions.EchoToOutput();


Apparently this always writes the output to the top of the page, even before the opening html tag, regardless of where the snippet is placed on the page. Which throws an error if the page is opened in a popup, by the way. Digging through the help file (because the MVCFunctions library is undocumented and every time someone asks about t we're told not to use them, even though they are given as examples all over the place!) I finally figured out that you must use MVCFunctions.Echo() to get the output at the location of the code.
So now it's working.
Yes, I'm a bit frustrated. It's ridiculous that I had to waste 2 hours figuring how to do something simple because of incorrect and missing documentation.

admin 3/18/2020

Pete,
thank you for pointing, we'll update the documentation.

Pete K author 3/19/2020



Pete,
thank you for pointing, we'll update the documentation.


Thanks, Sergey.