Problem Refreshing App IFrame

Following the exmple in Scriptcase WebSite i create a container application with a Control in one widget and a Grid Application in another one.
I write this JavaScript code on a Button to refresh the Grid Application (Showing the Summary only) with the parameters set by the user.

[B]url = "../COMPARATIVO_VENTAS_SUCURSAL/COMPARATIVO_VENTAS_SUCURSAL.php?desde='" + document.getElementById('id_sc_field_fecha_desde').value + "'&hasta='" + 
document.getElementById('id_sc_field_fecha_hasta').value + "\'";
alert(url);
parent.document.getElementById('id-iframe-widget2').contentWindow.document.location.href = url;[/B]

In the ScriptInit Event of the Grid Application i have this code.

if (isset($_GET['desde'])) {
	$DESDE =  $_GET['desde'];
	[BEGIN_DATE] = $DESDE;
} else {
	[BEGIN_DATE] = ' DATEADD(DD,0,DATEDIFF(DD,0,GETDATE())) ';
}
if (isset($_GET['hasta'])) {
	$HASTA = $_GET['hasta'];
	[END_DATE] = $HASTA;
} else {
	[END_DATE] = ' GETDATE() ';
}

And this is my query

[B]SELECT
	R.BRANCH AS SUCURSAL,
	R.AMOUNT AS MONTO,
	DATEADD(DD,0, DATEDIFF(DD,0,R.DATETIME)) AS FECHA,
	DATEPART(YEAR, R.DATETIME) AS ANO,
        CONVERT(varchar(5),r.datetime,103) AS DIAMES
FROM RETAIL R
WHERE (DATEADD(DD,0, DATEDIFF(DD,0,R.DATETIME)) BETWEEN [BEGIN_DATE] AND  [END_DATE])
OR (DATEADD(DD,0, DATEDIFF(DD,0,R.DATETIME)) BETWEEN DATEADD(YY,-1,[BEGIN_DATE] ) AND DATEADD(YY,-1, [END_DATE]))[/B]

The problem is that the first time i click the button the iframe reloads the content, receives the parameter but the grid is not updated.
If i click the button one more time everything works fine.
I check with Echo function that parameters are arriving well both times i click the button.
Any idea what can i do?

I think that the problem lies into the use of global variables. These variables needs to be passed too. Not quite sure, but it looks like a similar issue I had with using sc_redir to another application (in fact an iframe) an I had to put the global variable in the sc_redir call to get things working.

Aducom,
Thanks for your answer.
What do you mean with passed?

I use the URL (Get Method) to pass the filter values and i set the variables on the onScriptInit event.
I have another app that refresh 4 iframes, sometimes all of them refresh ok and sometimes 1 or 2 don’t. That app shows only the graphic of a Grid Application.

Regards,
Maxi

I think the problem is with the Global Variables.
Sometimes when i first load the Site it throws a SQL error because the variables are empty even when in my code i always set a value for each variable and the query fails to execute. Like the variables are not passed correctly to the Query.
Does anyone have any tip?

I’m Stucked at this point…
I appreciate any help.

Regards,
Maxi