ShowModalDialog

M

MW de Jager

I want to call ShowModalDialog(...) from my C# code in the code behind page
of my aspx page. I do not want to link this to a button, since I want to
first do some checking myself before I call the showModalDialog. I also
want to receive a result back from the ShowModalDialog when it is closed.

My problems are currently these:

(1) If I call the showModalDialog using RegisterClientScriptBlock, then I
have no way of receiving a return value in C# or VB.
(2) If I showed my html page using showModalDialog, then window.close() does
not seem to close the dialog and give control back to the aspx page that
called the showModalDialog script.

All help will be appreciated
MW
 
M

MW de Jager

Thanks for your reply Eliyahy

There are quite a number of things that are still unclear to me.

How does the server side code signal to its client counterpart to call
showModalDialog? Do I need to code Javascript inside the html of my aspx
page that recognises that the hidden control has received a certain value?
This is exactly why I want to code in C#, because my scripting is not good
at all. Anyway, if this is what you are sugesting, how do I do it?

I've done the following:
created 2 server controls
Hidden1.Value = "";
Hidden2.Value = ""; // initially

After checking what needs to be checked on the server side code, I set
Hidden1.Value = "MyDialog.htm";


Now to do the comparison in Javascript:

<SCRIPT language="JavaScript">
.....
if (Hidden1.value != "")
Hidden2.value = showModalDialog(Hidden1.value);
.....
<SCRIPT />

My question is this. Where do I put this Javascript of mine so that it
executes when the server side changes the value of Hidden1? and where on
the server side do I need to put the code to check when Hidden2.Value
change?

Thanks again for your help thus far
MW
 
E

Eliyahu Goldin

The server-side code can signal to its client counterpart to call
showModalDialog. A hidden input control is good for that. The server sets an
action code in the hidden input, the client gets the value in body's onload
event and execute the action. In your case the action is a call to
showModalDialog.

showModalDialog is a client-side function. As such, it will always return
the result value to the calling CLIENT function. The calling function can
pass the result over to the server in one of several standard ways of
passing information from client to server, e.g. in another hidden input
control.

Eliyahu
 
M

MW de Jager

Thanks Eliyahu

You have been of great help!

MW

Eliyahu Goldin said:
By passing values in a hidden input control.

So wasn't mine. It improved when I realized that there's no other way of
creating usable web applications.

Very good. You will need to prefix Hidden1, Hidden2 with the form id, like
Form1.Hidden1, Form1.Hidden2.

Put your script block inside <head> section of your .aspx page. Make a
function
<head>
...
<SCRIPT language="JavaScript">
....
function onLoad(){
if (Form1.Hidden1.value != "")
Form1.Hidden2.value = showModalDialog(Hidden1.value);
}
....
<SCRIPT />
...
</head>
and add onload attribute to the body tag:

In any part of the code where you need it. In Page_Load event? Any other
event? Whatever you want.

You are welcome.
 
E

Eliyahu Goldin

How does the server side code signal to its client counterpart to call
showModalDialog?
By passing values in a hidden input control.
Do I need to code Javascript inside the html of my aspx
page that recognises that the hidden control has received a certain value? yes.

This is exactly why I want to code in C#, because my scripting is not good
at all.
So wasn't mine. It improved when I realized that there's no other way of
creating usable web applications.
Anyway, if this is what you are sugesting, how do I do it?

I've done the following:
created 2 server controls
Hidden1.Value = "";
Hidden2.Value = ""; // initially

After checking what needs to be checked on the server side code, I set
Hidden1.Value = "MyDialog.htm";


Now to do the comparison in Javascript:

<SCRIPT language="JavaScript">
....
if (Hidden1.value != "")
Hidden2.value = showModalDialog(Hidden1.value);
....
<SCRIPT />
Very good. You will need to prefix Hidden1, Hidden2 with the form id, like
Form1.Hidden1, Form1.Hidden2.
My question is this. Where do I put this Javascript of mine so that it
executes when the server side changes the value of Hidden1?
Put your script block inside <head> section of your .aspx page. Make a
function
<head>
....
<SCRIPT language="JavaScript">
....
function onLoad(){
if (Form1.Hidden1.value != "")
Form1.Hidden2.value = showModalDialog(Hidden1.value);
}
....
<SCRIPT />
....
</head>
and add onload attribute to the body tag:
and where on
the server side do I need to put the code to check when Hidden2.Value
change?
In any part of the code where you need it. In Page_Load event? Any other
event? Whatever you want.
Thanks again for your help thus far
You are welcome.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top