Solved

Using getElementById to update parent page without reloading

Posted on 2004-09-22
3
4,629 Views
Last Modified: 2008-02-01
Hi!

I have 2 pages Main.aspx and detail.aspx. The first page is a DIV The second page(detail.aspx) is an IFRAME.
When I click the edit button on the main page, it opens up the Iframe on the bottom.
When I update the individual record in the iframe on the bottom, should update the record on Main.aspx without reloading.

So I use getElementById() to get the values and assign them to the parent document.
The problem occurs when I want to use parent.document.getElementById()   or window.opener.document.getElementById()
here is a snippet.

<SCRIPT language ="javascript" id="UpdateMain">
            function UpdateMain() {
            for (i=0; i < document.all.length; i++)
            //storeid =stid ; customerid = custid  Detailid = checkbox.checked status
            var stid= document.getElementById('txtStoreID').value
            var custid= document.getElementById('TxtCustomerName').value
            var Detailid = document.getElementById('chkcontacted').checked

            var idSearch= window.parent.document.body.id
            //alert("My id is  : " + idSearch + " " )
                  
      //using DHTML document.getElementById Method to update Parent            
      window.parent.document.getElementById('DataGrid1__ctl[i]_IContacted').value=Detailid;
                  alert("The Current Status  For : " + stid + " " + custid + " is " +  Detailid  );
            //using url to update parent.
      //var url = 'Main.aspx?storeid=stid&Customerid=custid&DataGrid1__ctl[i]_IContacted.checked=Detailedid';
      //      location.href=url;
                  }

            </SCRIPT>

Your help is appreciated.
0
Comment
Question by:externet
  • 2
3 Comments
 

Author Comment

by:externet
ID: 12137179
There was a typo in the previous message:  'DataGrid1__ctl[i]_IContacted' should have been 'DataGrid1__ctl'+[i]+'_IContacted'.  

This block is now  //using DHTML document.getElementById Method to update Parent
             parent.document.getElementById('DataGrid1__ctl'+[i]+'_IContacted').value=document.getElementById('chkcontacted').checked;

when I click submit in the iframe, the parent is updated but the display in the div  does not refresh. Why?

             
0
 
LVL 15

Accepted Solution

by:
Thogek earned 500 total points
ID: 12191960
The above function looks very confused.  You have three distinct variables you are accessing ('txtStoreID', etc.), the first of which is under a for-statement (no braces means only the first line under the for is looped).  You then later set one of these values to an indexed control in the parent page 'DataGrid1__ctl[i]_IContacted'....  Looks very muddled.

Can you check that this is indeed the exact code that you are running (i.e., that appears in the "View Source" HTML of the page), and post exactly what *is* happening when you run it?
 
0
 

Author Comment

by:externet
ID: 12199502
Hello Thogek,
Thanks for your suggestions. I  have had a solution which is as follows:
function UpdateMaster() {
            <!--
            var stid= document.getElementById('txtStoreID').value
            var custid = document.getElementById('txtCustomerID').value
            var chkValue = document.getElementById('chkcontacted').checked
            var currentId = stid + "_" + custid
            parent.document.getElementById(currentId).children[0].checked=chkValue;
            
             }
      -->
      </script>
I had two Issues: The Datagrid control associates itself to the elementid.  So I Inserted a checkbox control within a <span> to maintain my id (stid + "_" + custid) unique and free from the datagrid control.  Every works now as expected.
The second issue as you indicated was my for- statement which you indicated from your reply.  
Again Thanks.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

838 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