Patrik Löwendahl said:
Try to write out the script directly to the page after the save of data.
<code>
private void butSaveOrder_Click(object sender, System.EventArgs e)
{
DataSavings dtSave = new CMSDataViewer.Utilities.DataSavings ();
dtSave.SaveSortOrders(false,HiddenIds );
Response.Write("<script language=\"Javascript\">window.opener =
self;window.close();</script>");
Response.End();
}
</code>
The window.opener = self statement is to bypass the annoying message box
that IE throws at you when trying to close a window from javascript.
--
Patrik Löwendahl
cshrp.net - " Elegant code by witty programmers "
cornerstone.se - " IT Training for professionals "
butSaveOrder.Attributes.Add("onclick", "ClosePopUp()");
Excellent! Thanks folks for the suggestions. I played with each of the
suggestions and turns out the the suggestion by N does what exactly
what I need. Bingo!
Code below with the last line being the one for others to use in this
situation.
Patrick's suggestion helped in that it did not throw up the extra
form, so I could have used it in the save and gotten rid of the close
button. The user could still close using the control box.
I played with the things Juan suggested but no go.
***********************************************************************************************
private void butSaveOrder_Click(object sender, System.EventArgs e)
{
DataSavings dtSave = new CMSDataViewer.Utilities.DataSavings ();
dtSave.SaveSortOrders(false,HiddenIds );
/*
//Suggestion 1 (Patrick): Saves but does not close PopUp(At least
does not Open another window).
Response.Write("<script language=\"Javascript\">window.opener
= self;window.close();</script>");
Response.End();
//Suggestion 2 (JUan):My Original with Navigate before Close and the
ClosePopUp used consistently
if( !Page.IsClientScriptBlockRegistered ("ClosePopUp"))
{
RegisterClientScriptBlock("ClosePopUp", "<script
language=\"javascript\">function
ClosePopUp(){window.history.back();window.close(); };</script>");
}
butSaveOrder.Attributes.Add("onclick", "ClosePopUp()");
*/
//Suggestion 3 (N). This does the trick: - uses <base target="_self">
in page header:
RegisterStartupScript("winclose","<script>window.close();</script>");
}
***********************************************************************************************
Thanks again. Grant