Concept
Whenever you open a window from the main page, keep a reference to the opened window (pushing it onto an array works well). When the main page button is clicked, close each referenced window.
Client Script
This JavaScript is for the main page. This works for an HTML or ASPX page.
var arrWindowRefs = [];
//... assume many references are added to this array - as each window is open...
//Close them all by calling this function.
function CloseSpawnedWindows() {
for (var idx in arrWindowRefs)
arrWindowRefs[idx].close();
}
Opening a window and pushing it onto the above array looks something like this:
// Spawn a child window and keep its reference.
var handle = window.open('about:blank');
arrWindowRefs.push(handle);
Microsoft's JavaScript window.open(..) method and its arguments are outlined here.
Different browsers might have variations or proprietary ways to keep references to opened windows or to enumerate through them, but this pure JavaScript way is very compatible with browsers.
Button
Finally the HTML Input button to initiate the above code would be
<input type="button"
name="btn1" id="btn1" value="Click Me To Close All Windows"
onclick="CloseSpawnedWindows()">
If it's an ASP.NET Button Control then call JavaScript this way
<asp:Button ID="Button1" runat="server" Text="Click Me To Close All Windows"
OnClientClick="CloseSpawnedWindows()" />
Troubleshooting ASP.NET client script (PostBack and AJAX fix)
If your aspx page posts back to the server, the client code will be destroyed and lose it's array with child window references (and those windows will remain open). If this is a concern, you might want to use AJAX for partial page refreshes, to prevent the entire page and its scripts from being destroyed.
(Shown using Framework 3.5 samples)
For ASP.NET AJAX you'll be using something like a ScriptManager instance to enable partial page refresh inside UpdatePanel controls (lots of samples).
<%@Page... %>
<asp:ScriptManager EnablePartialRendering="True" /> Enable AJAX.
<script>
// PUT JAVASCRIPT OUT HERE SOMEWHERE.
// Notice the client script here is outside the UpdatePanel controls,
// to prevent script from being destroyed by AJAX panel refresh.
</script>
<asp:UpdatePanel ID="area1" runat="server" ... > ... </asp:UpdatePanel>
<asp:UpdatePanel ID="area2" runat="server" ... > ... </asp:UpdatePanel>
etc...
A lot more detail about ASP.NET AJAX can be provided but this is just a start in case you need it.
Remember, in the case of AJAX, don't refresh the part of the page containing the above Client Script because you want it to persist the array through server callbacks.