 |
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
|
|
|

November 20th, 2003, 07:00 AM
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|

November 20th, 2003, 07:06 AM
|
Registered User
|
|
Join Date: Nov 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yes, It is possible if you use JavaScript.
Just call window.opener.parentFormName.parentFormControlName .parentFormControlPropertyName.value='xyz';
Thanks,
Abhijit
|

November 20th, 2003, 07:27 AM
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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'
|

November 20th, 2003, 07:34 AM
|
Registered User
|
|
Join Date: Nov 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The parent form, where btnTest exists. Not the Form of the Modal window. Am I clear ?
|

November 20th, 2003, 07:37 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Is this being done in ASP.Net by any chance?
Peter
------------------------------------------------------
Work smarter, not harder.
|

November 20th, 2003, 07:46 AM
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

November 20th, 2003, 08:00 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
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.
|

November 20th, 2003, 08:39 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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
|

November 21st, 2003, 05:03 AM
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Joe - that worked!
var opener = window.dialogArguments;
opener.Form1.btnTest.value='xyz';
|

November 26th, 2003, 11:42 PM
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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...)
|
|
 |