beakersoft
beakersoft

Reputation: 2356

Redirecting a ASP.Net page after opening a new window

I have got some code at the end of a button click event that uses RegisterStartupScript to open up a new Windows (its to a report for the user to print of)

After the page has loaded i would then like to re-direct the user away from the data entry page back onto the default page, but if i put a Response.Redirect in it does not open up my popup window. Any idea why the popup would not fire?

This is the c# code:

string myRptURL = "EstimateReport.aspx?id=" + hiddenID.Value;
                string script = "window.open('" + myRptURL + "','')";

                ClientScript.RegisterStartupScript(this.GetType(), "OpenWin", "<script>openNewWin('" + myRptURL + "')</script>");
                Response.Redirect("default.aspx?mess=" + Server.UrlEncode("New Estimate Created"));

and this is the Javascript function:

<script language="javascript" type="text/javascript">

function openNewWin(url) {
    var x = window.open(url, 'mynewwin', '_blank', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=520,modal=yes,alwaysRaised=yes');
    x.focus();
}

Upvotes: 3

Views: 2254

Answers (1)

Amiram Korach
Amiram Korach

Reputation: 13286

The Response.Redirect is canceling the script since it is not being sent to the client. redirect in javascript instead.

ClientScript.RegisterStartupScript(this.GetType(), "OpenWin",
 "<script>openNewWin('" + myRptURL + "','" + "default.aspx?mess=" +
 Server.UrlEncode("New Estimate Created") + "')</script>");

function openNewWin(url, redirectUrl) {
    var x = window.open(url, 'mynewwin', '_blank', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=520,modal=yes,alwaysRaised=yes');
    x.focus();
    window.location = redirectUrl;
}

Upvotes: 3

Related Questions