Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript_howto thread: refreshing a ModalDialog


Message #1 by "Noreen M Masterson" <noreen_masterson@s...> on Wed, 15 Jan 2003 15:17:51
Yes there's no problem for this the dlg could submit a form of the opener.
Just get a handle on the form using the handle on the opener from the dlg.
What happens to the handles depends on where the variable is stored. If you
unload the page and the variable is stored into it you'll loose the handle.
If you're using frames for exemple and storing the variable on top of opener
(in the frameset) the handle will always be there. Just take care of
clearing the handle when closing the dlg.

In fact I think that we could say that the opener is really doing things, as
the dlg just call a function and all the process is done in the opener.

I use this kind of thing because I've a very big web application, so most of
main fonctionalities are stored in the top of it (frameset) => to execute
some standard operation we just have to generate a call to these functions
=> opening a chapter, updating / inserting a record...

To update a reccord I can have my dlg just calling a function in the
application saying "update the current reccord", the application then excute
the function that will get all infos and submit them to the server for
processing, return values and update the interface.

The fact that the dlg is modal just stop the current running function but
you can continue to access the opener. and of course you can't unload the
calling page because as the page is running untill the dlg close. I avoid
this having my OpenDlg function stored in my menu bar which could never be
unloaded as long the application is running.

Having handles on both side allow to have my dlg to be able to access all
the application functionalities and to use generic code in the application
and not code dedicated to each dlg.

I just have a function OpenDlg with standardized parameters and if the dlg
needs more info from the application that's the dlg itself that get what he
needs => all logic is inside the page where it's used.

Try this:
calling from top frame, the dlg can submit the bottom frame but calling from
bottom frame the post is delayed as long the dlg is opened. (in fact it
event crash my browser but that's not important as that's a thing that can't
be done)
frameset:
<HTML>
<HEAD>
</HEAD>
<frameset rows="*,*">
<frame name=fraMain src="ASPPage1.asp">
<frame name=fraSub src="ASPPage1.asp">
</frameset>
</HTML>


ASPPage1.asp
<HTML>
<HEAD>
<script>
function OpenDlg()
{
 arrParam = [top,document.getElementById('txt1')]
 window.showModalDialog("ASPPage2.asp",arrParam)
}

function UseValue(p_value)
{
  top.hndMyDlg.document.getElementById('txt1').value = "Return " +
top.hndMyDlg.document.getElementById('txt1').value
}
</script>

</HEAD>
<BODY>
<form name="frmMain" action="ASPPage3.asp" method="post">
<input id=txt1 name=txt1>
<input id=txt2 name=txt2>
</form>
<button onclick=OpenDlg()>...</button>
</body>
</HTML>


ASPPage2.asp
<HTML>
<HEAD>
<script>
dlgOpener = window.dialogArguments[0]
dlgParam1 = window.dialogArguments[1]
dlgOpener.hndMyDlg = this

function init()
{
 document.getElementById('txt1').value = dlgParam1.value;
}
</script>
</HEAD>
<BODY>
<body onload=init()>
<input id=txt1>
<button
onclick=dlgOpener.fraMain.UseValue(document.getElementById('txt1').value)
id=button1 name=button1>...</button>
<button
onclick="dlgOpener.fraSub.document.getElementById('frmMain').submit()"
id=button2 name=button2>Submit</button>
</body>
</BODY>
</HTML>


ASPPage3.asp
<HTML>
<HEAD>
<script>
top.hndMyDlg.document.getElementById('txt1').value = 'hello back'
</script>
</HEAD>
<BODY>
<%
Response.Write (Request.Form("txt1"))
Response.Write (Request.Form("txt2"))
%>
</BODY>
</HTML>


"Van Knowles" <vknowles@s...> wrote in message
news:253125@j..._howto...
>
> Fabrice, I am intrigued.
>
> I guess the way I think of it, in your example the dialog is running
> script in the opener, but the opener itself isn't "doing" anything.  The
> dialog is doing things to the opener.
>
> My question is, could the dialog run a script in the opener that submits
> the opener's form, all while the dialog is still open?  (and what does
> that do to the handles on both sides?)
>
> -Van
>
> ---- Original message -------
> sure but for this just use the standard return value of the modal dlg.
>
> What having pointer allows is more like "I open a dlg, the user use it,
> then
> the dlg get a value from the opener to make treatment refresh himself
> according the value and set a global variable in the opener then make
> further processing... and when closing the dlg the opener is updated with
> more than 1 return value from the dlg"
>
> or "the opener is the main page which centralize a lot of top level
> javascript function that the dlg could call for use in the dlg itself"
>
> or "the dlg get a value then call a function in the opener which make some
> processing and return the value to the dlg..."
> ..
>
> The point is that once your dlg have a pointer on the dlg and the dlg on
> the
> opener you can freely comunicate between the two.
>
> That's just the calling script IS blocked until the dlg close.
>
> Eg:
> window.showModalDialog("MyDlg.asp")
> valueBack = hndMyDlg.document.getElementById('txt1').value
>
> won't work as after the showModalDialog the function wait that the dlg is
> closed
>
> BUT
>
> Try this code just to get an idea:
> Main page code:
> <HTML>
> <HEAD>
> <SCRIPT LANGUAGE=javascript>
> function UseValue(p_value)
> {
>     hndMyDlg.document.getElementById('txt1').value = "Return " +
> hndMyDlg.document.getElementById('txt1').value
> }
>
> function callDlg()
> {
>  openerParam = [this, document.getElementById('txt1')]
>
>  window.showModalDialog("MyDlg.asp",openerParam)
> }
> </SCRIPT>
> </HEAD>
> <BODY>
> <input id=txt1>
> <button onclick=callDlg()>...</button>
> </BODY>
> </HTML>
>
> MyDlg.asp code:
> <HTML>
> <HEAD>
> <script>
> dlgOpener = window.dialogArguments[0]
> dlgParam1 = window.dialogArguments[1]
> dlgOpener.hndMyDlg = this
>
> function init()
> {
>  document.getElementById('txt1').value = dlgParam1.value;
> }
> </script>
> </HEAD>
> <BODY>
> <body onload=init()>
> <input id=txt1>
> <button
> onclick=dlgOpener.UseValue(document.getElementById('txt1').value)
> >...</butto
> n>
> </body>
> </BODY>
> </HTML>
>
>
>
>



  Return to Index