 |
| HTML Code Clinic Do you have some HTML code you'd like to share and get suggestions from others for tweaking or improving it? This discussion is the place. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the HTML Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

December 1st, 2003, 07:55 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Does anyone know how to do the same thing using server-side code?
I've tried putting the script inside a Response.Write command, but it isn't able to recognise Form1 any more, and gives an error message:-
Response.Write("<script>var opener = window.dialogArguments; opener.Form1.btnTest.value='xyz';</script>");
Cheers,
Gary
|
|

December 1st, 2003, 10:39 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I've sussed it now. The following line works:-
Response.Write("<script>window.dialogArguments.ope ner.Form1.btnTest.value='xyz';</script>");
|
|

December 2nd, 2003, 09:21 PM
|
|
Registered User
|
|
Join Date: Dec 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
MK, It looks like I'm trying to do the same thing as you (Open a modal dialog and return user input to the main page in server code), but I can't seem to get it to work... I use the Response.Write command to open the modal dialog (passing self as the dialog argument), then from the dialog I use Response.Write once again to try to pass a value back to a field on the 'parent' page. No matter what I do, I always get an error about the field being null, or not an object. I know the form name and the field id are correct because it works just fine when I use the window.open method to do the same.
Here's some code from the parent page:
string urlstring = ResolveUrl("dialogs/PhoneCall.aspx?FirstName=" + Server.UrlEncode(this.tbFirstName.Text.Trim()))
+ "&LastName=" + Server.UrlEncode(this.tbLastName.Text.Trim()) + "&HomePhone=" + Server.UrlEncode(this.tbHomePhone.Text.Trim())
+ "&BusinessPhone=" + Server.UrlEncode(this.tbBusinessPhone.Text.Trim()) ;
string features = "help=yes;";
string sScript = "<script language=javascript>var myWindow = window.self;var vReturn = window.showModalDialog('" + urlstring + "', myWindow, '" + features + "')</script>";
Response.Write(sScript);
And from the dialog page:
string sScript = "";
// Pass comment back to main page
sScript += "<script language=javascript>";
sScript += " var opener = window.dialogArguments;";
sScript += " opener.PageForm.tbComment.value = '" + this.tbCallComment.Text + "';";
sScript += " window.close();";
sScript += "</script>";
// Write script string to browser
Response.Write(sScript);
Any ideas why this isn't working for me?
|
|

December 3rd, 2003, 04:22 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
There were two things I found when trying to get my code to work:-
1) The control on the main page needs to be an HTML control with runat=server set, as opposed to WebForms control.
2) In the script I was sending with Response.Write, whenever I declared any variables it did not seem to work. That is why I replaced:-
Response.Write("<script>var opener = window.dialogArguments; opener.Form1.btnTest.value='xyz';</script>");
with:-
Response.Write("<script>window.dialogArguments.ope ner.Form1.btnTest.value='xyz';</script>");
...and that worked fine.
Try re-writing your code so it reads:-
sScript = "<script language=javascript>window.dialogArguments.PageFor m.tbComment.value = '" + this.tbCallComment.Text + "';window.close();";
";
Hope this helps,
Gary
|
|

December 3rd, 2003, 04:25 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
...Sorry that should have read:-
sScript = "<script language=javascript>window.dialogArguments.PageFor m.tbComment.value = '" + this.tbCallComment.Text + "';window.close();</script>";
";
|
|

December 3rd, 2003, 01:07 PM
|
|
Registered User
|
|
Join Date: Dec 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
GP_MK, thanks for the response! I tried what you suggessted, and I'm still running into the same problem. The fact that the problem goes away when I use window.open as opposed to window.showModalDialog is what's really weird... for some reason with the Modal Dialog the PageForm object is undefined... Oh well, I'll just have to try another way. Thanks for the help!
PP
|
|

January 2nd, 2004, 07:17 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Does anyone know how to do this from server code? The opening of the dailog box can be done easilly enough using RegisterStartupScript or Response.Write
However, when I pass "self" into showModalDialog it seems to pass in a null reference, so I am unable to set "var opener = window.dialogArguments" and therefore am unable to obtain a reference to the parent form.
To open dialog from server:-
script = "<script>window.showModalDialog('dialog.aspx', self, 'dialogHeight:432px;dialogWidth:598px;center:yes;h elp:no;scroll:no;status:no')</script>";
this.RegisterStartupScript("xxx", script);
To set a property on parent form:-
var opener = window.dialogArguments;
opener.Form1.btnTest.value='xyz';
Cheers,
Gary
|
|

January 20th, 2004, 06:24 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I still haven't found a solution to this problem yet. As this topic is now quite long, I'll summarize the problem to make it more readable. Hopefully someone will have an answer:-
I need to :-
1) Open a modal dialog box using RegisterStartupScript
2) When the user clicks on a button on the dialog, I need to update certain controls on the parent page - with the dialog box still open.
The problem is getting a reference to the parent page. This is difficult with a modal dialog box as "window.opener" does not exist. If I had opened the dialog from client script I could pass "self" in as an argument and then obtained a reference to the parent using "var opener = window.dialogArguments". Unfortunately, when the script originates on the server (i.e. is called via RegisterStartupScript), "self" is null so I can't use it!
Sadly, opening the dialog box from client script is not an option.
If anyone has a solution, or can think of a different way of doing this I would be very grateful!
Cheers,
Gary
|
|

January 20th, 2004, 10:19 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Can I see the output generated by your aspx page when it shows in the browser. Revove any extraneous material if possible if it's large?
--
Joe
|
|

January 21st, 2004, 06:06 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Joe,
Thanks for your reply.
Do you want to see the output from the main page or the dialog box? I could send both, but as they are quite big I just thought I'd check first.
|
|
 |