Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > HTML > HTML Code Clinic
|
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
 
Old December 1st, 2003, 07:55 AM
Authorized User
 
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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


 
Old December 1st, 2003, 10:39 AM
Authorized User
 
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've sussed it now. The following line works:-

Response.Write("<script>window.dialogArguments.ope ner.Form1.btnTest.value='xyz';</script>");


 
Old December 2nd, 2003, 09:21 PM
Registered User
 
Join Date: Dec 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?


 
Old December 3rd, 2003, 04:22 AM
Authorized User
 
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old December 3rd, 2003, 04:25 AM
Authorized User
 
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

...Sorry that should have read:-

sScript = "<script language=javascript>window.dialogArguments.PageFor m.tbComment.value = '" + this.tbCallComment.Text + "';window.close();</script>";
";

 
Old December 3rd, 2003, 01:07 PM
Registered User
 
Join Date: Dec 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old January 2nd, 2004, 07:17 AM
Authorized User
 
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old January 20th, 2004, 06:24 AM
Authorized User
 
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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





 
Old January 20th, 2004, 10:19 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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
 
Old January 21st, 2004, 06:06 AM
Authorized User
 
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.







Similar Threads
Thread Thread Starter Forum Replies Last Post
Forcing postback on parent page from modal dialog gp_mk ASP.NET 1.0 and 1.1 Professional 8 February 20th, 2007 12:44 PM
how to return value from modal dialog ajaypsingh Javascript 2 May 16th, 2006 05:14 AM
Modal Dialog window Problem anandham Javascript 7 February 16th, 2005 06:08 PM
Scrolling modal dialog to top gp_mk HTML Code Clinic 3 September 15th, 2004 07:04 AM
Modal dialog window eldanh ASP.NET 1.0 and 1.1 Basics 0 August 10th, 2004 02:07 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.