PDA

View Full Version : Refreshing Parent Window in an ASP .NET web form.


Ventura1
11-28-2005, 09:54 AM
Hello,

I was wondering if anyone can help, I have a script that is attached to the onclick event of button on my web form. The web form is an edit page which is in the form of a popup window, I use this script so that when the popup is closed the parent form refreshes and the data is reloaded.

The problem I have is that I call this popup from two seperate locations in my system and only one of them has the element "ScheduleControl_txtRefresh", obviously I could add this to the other form and let the script force a postback however this isn't what I want to achieve, I want to simply close the form without refreshing the parent when no element is found.

Here is my current script...

<script language="JavaScript" type="text/javascript">
function CloseRefreshParent()
{
var x=window.opener.document.getElementByID("ScheduleControl_txtRefresh");
x.value = "True";
window.opener.document.forms[0].submit();
window.close();
}
</script>


Thanks very much!

glenngv
11-29-2005, 04:27 AM
function CloseRefreshParent()
{
if (opener && !opener.closed) { //check if opener window is still open
var x = opener.document.getElementById("ScheduleControl_txtRefresh");
if (x) { //check if field exists
x.value = "True";
opener.document.forms[0].submit();
}
}
window.close();
}

Ventura1
11-29-2005, 10:22 AM
That is fantastic, it does exactly what I wanted it to do!

Thanks very much Glenn!