CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> ASP

 "Submit" also executes code from "Before Show" event

Print topic Send  topic

Author Message
mariusdr

Posts: 21
Posted: 05/10/2013, 3:13 PM

This is a record, I have code in the 'Before Show' event which sends the fields to a web service, receives an answer which is placed in a text area. Initially I had another event, On Load - Submit Form which was supposed to send this text area and a couple other fields to a SQL database, by executing a Stored Procedure (defined in Custom Update). I took this event off, because the page was looping, writing to SQL until the columns was full. Now, without the On Load - Submit page event, if I Submit the page myself, not only it executes the SP, but it also re-executes the Before Show code... how can that be, what am I doing wrong? thanks!
View profile  Send private message
Lucius

Posts: 220
Posted: 05/10/2013, 3:56 PM

This behavior from your description is correct. When page is refreshed the Before Show event is always triggered. Doesn't matter how you got to that page - that you clicked on a link, submitted a form, etc.. Page refreshes - you get Before Show event on the newly displayed page.

View profile  Send private message
mariusdr

Posts: 21
Posted: 05/10/2013, 5:36 PM

yes, that sounds right.. i should have thought about it.
I guess I still have to figure out why I have the looping when I have both events, On Load - Submit Form and Before Show - Custom Code. My Custom code does not or should not submit the form. Actually, I just tried it, I deleted Before Show - Custom Code, and it still loops, even though I only have the one event left (On Load - Submit Form). So, every time the it gets submitted, it refreshes and it does the Submit again? That means, I am not using the event correctly? Thanks for your help, it is much appreciated, as I am totally new to web development.
View profile  Send private message
mariusdr

Posts: 21
Posted: 05/10/2013, 5:51 PM

Finally, I'm getting it.. I should make it open a different page (Return page) if I use the on load - sub mit form, otherwise it will loop... Thanks again!
View profile  Send private message
Lucius

Posts: 220
Posted: 05/11/2013, 8:59 AM

Or if you wish to use only one page you can add a URL GET parameter to your grid, that will be set to some vale telling you, you have a form submission. Or just check any required value that is passed from your form - for example some table ID (even easier).

In any case if such flag/value is passed, then you know where this event is coming from, then do a simple if... else.. code to only execute your code when needed.
View profile  Send private message
mariusdr

Posts: 21
Posted: 05/13/2013, 7:08 PM

here is what I'm trying to accomplish: a page gets popultade with data from a SQL database (1 row per 1 record screen, linked to from a Search page). The operator may add to modify the data, when we hits 'submit' the Custome Upadte runs a SP that updates the data in SQL, then an "after update" event first send the data to a webservice (mainframe), then, depending on the result, executes another SP (programaticaly), updating SQL again with the result from the web service update.
Ideally, I would retrieve the data from SQL, let the operator change it, then execute the code for the webservice update first, look at the result, then update SQL running a single SP, with all that data (changed by operator + result of webservice response).
can you offer some advice on what events to use (combine) to get this accomplished? thank you!
View profile  Send private message
Lucius

Posts: 220
Posted: 05/14/2013, 8:50 AM

Its hard to say exactly which events, because I do not know your page setup. Lets assume that you have:

Grid (for data display)

Search form (connected to the grid)

Record form (that allows inserting and updating single record)

Ok, so anything related to the grid (data population) it would be Before Show event of the Grid component, or if you wish to keep all "display" code for all components in one place I would use After Initialize even for the Page.

Events that are related to data change should go into Record from events. Now if you do not use CCS Record events that are built into, as it is most likely the case with your Stored Procedure you can use:

- Button "On Click" server event - the code will execute after the button is clicked (most likely you will have 2 separate buttons for Insert and Update, so it will be 2 events)
or
- Record "Before Execute Update" and "Before Execute Insert" events. If you use those you need to make sure that the execution ends after you use your SP and webservice. This can be achieved by "return false;" at the end of your code - this will end the function and also should not launch the default CCS Update/Insert event.
View profile  Send private message
mariusdr

Posts: 21
Posted: 05/14/2013, 9:25 PM

I have a Search Grid, which retrieves a Record when clicking on a RowID.
I tried using the 'on click' for the Submit Button, then I realized it will try to write to SQL twice, once because of the CCS Submit event (fields have the SQL columns as a control source), and then again, in my custom code, on the 'on click' event.
Ideally, after loading the existing values from the SQL table in my record, and after the operator makes changes (I don't need an Insert, only update), I would execute the custom code that send teh fields to teh web service, check on teh response, and if it positive, then, write to SQL. Maybe I could keep the 'on click' for the Submit button and put in a Custom Update, a stored procedure which would oly update a flag, then write the rest to sql when I get the response from the web service (as described above). If you have a Custome Update, will that prevent the Submit to send all fields to the table? thank you!
View profile  Send private message
Lucius

Posts: 220
Posted: 05/15/2013, 8:51 AM

Custom Update will override the default way the records are updated, and will do what you designed. For example when I want to block default functionality I often use Custom Update Type property, set it to SQL, and write in the Custom Update property following SQL:

SELECT 1;

So now the default update action is blocked and I can use event Before Execute Update, to create my own Update logic.
View profile  Send private message
mariusdr

Posts: 21
Posted: 05/15/2013, 12:56 PM

That makes sense... thanks a lot!
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.