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 November 20th, 2003, 07:00 AM
Authorized User
 
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default Referencing parent page from modal dialog

I have a web page that opens a modal dialog box. From within this dialog box I need to change a property of one of the controls on the parent page (i.e. the page that opened the dialog box). Does anyone know if this is possible?




 
Old November 20th, 2003, 07:06 AM
Registered User
 
Join Date: Nov 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Abhijitsaha2000 Send a message via Yahoo to Abhijitsaha2000
Default

Yes, It is possible if you use JavaScript.

Just call window.opener.parentFormName.parentFormControlName .parentFormControlPropertyName.value='xyz';

Thanks,
Abhijit

 
Old November 20th, 2003, 07:27 AM
Authorized User
 
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Abhijit.

Unfortunalely, I can't seem to get it to work. What do I use in place of parentFormName? Is it the <form id="Form1" reference? When I use that it stops my dialog box from opening for some reason.
i.e. my statement reads:-

window.opener.Form1.btnTest.value='xyz'

 
Old November 20th, 2003, 07:34 AM
Registered User
 
Join Date: Nov 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Abhijitsaha2000 Send a message via Yahoo to Abhijitsaha2000
Default

The parent form, where btnTest exists. Not the Form of the Modal window. Am I clear ?

 
Old November 20th, 2003, 07:37 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Is this being done in ASP.Net by any chance?

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old November 20th, 2003, 07:46 AM
Authorized User
 
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, it is being done in ASP.NET.
I am getting a script error:
"Microsoft JScript runtime error: 'window.opener.Form1 is null or not an object".
Form1 is the name of the parent form.

 
Old November 20th, 2003, 08:00 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

In ASP.Net, when the <form> tag is rendered, it doesn't contain the name atribute. Even if you put one in there in the markup it won't make it into the rendered html. So, you need to reference the form by means of the document's forms array.

window.opener.forms[0].btnTest.value='xyz'

Keep in mind also that the button control name might not be consistent. If it's just on the ASPX directly then you shouldn't have a problem. Trying to write javascript that is compatible with ASP.Net can be very tricky because of the way ASP.Net names/ids the controls in the rendered HTML. Usually controls that are directly on the webform (i.e. NOT in user controls) are ok because their name attribute (which is what is required for javascript name accessibility) is set to the ID value you provided in the markup (<asp:* id="theControlID">).

When in doubt, look at the rended source and see what the final HTML looks like for the control.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old November 20th, 2003, 08:39 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

window.opener does not exist for modalDialog. You must pass refernce in when you open the dialog:
Code:
var vReturn = window.showModalDialog(<url here>, self, <features here>);
In your modal dialog page have the following code:
Code:
var opener = window.dialogArguments;


--

Joe
 
Old November 21st, 2003, 05:03 AM
Authorized User
 
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Joe - that worked!

var opener = window.dialogArguments;
opener.Form1.btnTest.value='xyz';

 
Old November 26th, 2003, 11:42 PM
Authorized User
 
Join Date: Jun 2003
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
Default

Just to provide a different perspective on the ASP.NET FORM tag issue:

On my system, ASP.NET renders both the NAME= and ID= attributes of the FORM tag. I've never seen it _not_ render these attributes. If you're using Visual Studio .NET, it automatically supplies the ID value "Form1" when you create a new standard web page.

The best thing to do, as Peter says, is to view the source when your page is rendered. My source always shows NAME="Form1" and ID="Form1".


-Van
(Old dog learning new tricks...)





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.