Dear all,
I can use this code to write a value in parent window control.

StrJScript = "<SCRIPT>parent.document.forms[0].TxtCustomerId.value = '" & ClearSpace(Row.Cells(1).Text.Trim) & "';</SCRIPT>"
        If Not ClientScript.IsClientScriptBlockRegistered("S1") Then
            ClientScript.RegisterClientScriptBlock(Me.GetType(), "S1", StrJScript)
        End If

but, I cannot set iFrame visible to false.
I use this code :

StrJScript = "<SCRIPT>parent.document.form1.iFrmCustomer.visible = False;</SCRIPT>"
        If Not ClientScript.IsClientScriptBlockRegistered("S4") Then
            ClientScript.RegisterClientScriptBlock(Me.GetType(), "S4", StrJScript)
        End If

Raised error like this parent.document.form1.iFrmCustomer is null or not an object

Thanks

Dani AI

Generated

Quick follow-up for , and :

Hiding or "closing" an iframe from inside depends on two things: whether the iframe and parent are same-origin, and whether you target the iframe element (in the parent DOM) rather than the document inside it. Calling the frame's window close method from within (browser window close) won't remove the iframe element in the parent. If your script can access the parent (same-origin), the simplest, most robust approach is to operate on the iframe element itself.

A compact same-origin approach (run inside the iframe) is to use the frameElement reference and remove or hide that element:

// inside the iframe, when same-origin with parent
var el = window.frameElement;
if (el && el.parentNode) {
  el.parentNode.removeChild(el); // fully removes the iframe element
}

If the iframe is cross-origin, use postMessage: the iframe posts a “please close” message and the parent listens and removes/hides the iframe. Example pattern:

// inside iframe (post a request)
window.parent.postMessage({ type: 'CLOSE_IFRAME', id: 'iFrmCustomer' }, 'https://parent.example.com');

// in parent (listen and act)
window.addEventListener('message', function(e) {
  if (e.origin !== 'https://iframe.example.com') return; // validate origin
  if (e.data && e.data.type === 'CLOSE_IFRAME') {
    var f = document.getElementById(e.data.id);
    if (f && f.parentNode) f.parentNode.removeChild(f);
  }
});

Troubleshooting notes: confirm same-origin (otherwise parent.document access is blocked), verify you are targeting the iframe element (not the inner document), check ASP.NET-generated client IDs (use ClientID or ClientIDMode="Static" if needed), ensure your code runs after the parent DOM exists, and inspect CSS (borders, wrapper containers or layout rules can leave visible gaps if only the iframe content was cleared). Use postMessage when in doubt for a clean, secure solution.

Recommended Answers

All 3 Replies

Have you tried this: <script> this.close() </script>

Done, I have solved that problem
I use this code :

StrJScript = "<SCRIPT>parent.document.getElementById('iFrmCustomer').style.display = 'none';</SCRIPT>"
  If Not ClientScript.IsClientScriptBlockRegistered("S4") Then
        ClientScript.RegisterClientScriptBlock(Me.GetType(), "S4", StrJScript)
  End If

Thanks Anyway...

The question is not solved yet. Actually "parent.document.getElementById('iFrmCustomer').style.display = 'none'" - this code will only clear the content of the iframe but the iframe window itself is not closing. Still the iframe is visible...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.