Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP .Net Finding a control on the parent window

Posted on 2004-04-07
16
Medium Priority
?
576 Views
Last Modified: 2007-12-19
Using Javascript in ASP .net I am attempting to alter the value of a control on the page that called the current page.  The current page is a dialog window.

I am finding the window this way
var d2 = window.parent.document.all;

and referring to the control this way
d2.hidDefaultServiceDetail

For some reason the above returns undefined.  The control definitely exists and I have definitely spelt it correctly (I copied and pasted the name).  I also can't access any other controls.  The control is a text box and is not in a container control of any kind.

Any Ideas?

0
Comment
Question by:JackieLee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
16 Comments
 
LVL 7

Expert Comment

by:dante469
ID: 10774224
Please remember JavaScript is case sensitive

hidDefaultServiceDetail is not same as HIDDEFAULTSERVICEDetail


If the control is in a form...  Since it is .Net it most probably is then ref like this...

Example assumes the Form the control is contained within is called      Form1   Please update to the name of your FORM if different...

var d2 = window.parent.document.all;
d2.Form1.hidDefaultServiceDetail;   'Where Form1 is the name of the form the control is contained within...

Have Fun,
Dante
0
 
LVL 1

Author Comment

by:JackieLee
ID: 10774383
d2.SupplierSearch is undefined
0
 
LVL 1

Author Comment

by:JackieLee
ID: 10774396
The window is a web form.  It's filename is SupplierSearch.aspx
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 7

Expert Comment

by:culshaja
ID: 10774532
Be careful with using document.all and document.Form1 in JavaScript to get access to a form element. If you are accessing a control that is within a UseControl or a repeater it will be prefixed with containercontrol_ and this will cause numerous problems. I would use .getElementByID if you know that you can rely on IE as your target browser. It gets past a lot of problems.

James :-)
0
 
LVL 1

Author Comment

by:JackieLee
ID: 10774729
How would one go about using .getElementByID  I can't find it.
0
 
LVL 7

Expert Comment

by:dante469
ID: 10774742
JackieLee,

Thanks for the reply...  I may have been ambiguous...

Not the webform name (SupplierSearch.aspx) but the <form> name of the form on that .aspx page ie...

<body>
      <form id="Form1" method="post" runat="server" onsubmit="return(chkuidpwd());">
            <asp:TextBox id="uid" runat="server"></asp:TextBox><BR>
            <asp:TextBox id="pwd" runat="server"></asp:TextBox></P>
            <asp:Button id="aspSubmit" runat="server" Text="aspSubmit" ></asp:Button>
      </form>
</body>

In the above the form is called Form1

Have Fun,
Dante
0
 
LVL 1

Author Comment

by:JackieLee
ID: 10774834
OK.  My form id is actually Form1.  I tried the following:
d2.Form1.hidDefaultServiceDetail
It is still undefined
0
 
LVL 1

Author Comment

by:JackieLee
ID: 10774908
I just noticed that the current form is also called Form1 so I changed it's id to Form2.  Now I get this error when I execute d2.Form1.hidDefaultServiceDetail

'd2.Form1.hidDefaultServiceDetail' is null or not an object
0
 
LVL 1

Author Comment

by:JackieLee
ID: 10774928
window.parent.document.all seems to reference the current window and not the parent window.  Is this because it's a dialog window?
0
 
LVL 22

Expert Comment

by:_TAD_
ID: 10774937
what about something like this (using code behind)

in this example I am looking for a textbox

                  foreach(Control ctrl in this.Controls)
                        if(ctrl.GetType()==typeof(TextBox))
                              if (((TextBox)ctrl).ID == "ID")
                                    --Found It
0
 
LVL 7

Expert Comment

by:dante469
ID: 10775053
simply ref as

window.parent.document.Form1.hidDefaultServiceDetail;

or

var parent = window.parent.document;
parent.Form1.hidDefaultServiceDetail;


Have Fun,
dante
0
 
LVL 1

Author Comment

by:JackieLee
ID: 10775144
Dante,

That doesn't work because:
window.parent.document.Form1 is undefined

The question is Why does window.parent.document refer to the current form and not the parent form?
0
 
LVL 7

Expert Comment

by:dante469
ID: 10775248
Sorry...  Assumed window.parent was working correctly....

How did you open the child...  Is it a frameset???

Have Fun,
Dante
0
 
LVL 7

Expert Comment

by:dante469
ID: 10775324
JackieLee,

Not sure how you are opening child however in anticipation of your answer;

showModelessDialog - allows interactivity between parent and child,

showModalDialog -   prevents the parent from directly interacting with the child, the child has the focus, hence the Modal name.

Have Fun,
Dante.
0
 
LVL 1

Author Comment

by:JackieLee
ID: 10781645
It's a modal dialog.  I need to be able to parse one piece of information back to the parent.  surely it's possible somehow.
0
 
LVL 6

Accepted Solution

by:
billy21 earned 1600 total points
ID: 10783152
Hi Jackie,

Try this:

var d = window.dialogArguments.document.all;

referencing this way of course:
d.hidDefaultServiceDetail.value = whatever
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question