简体   繁体   中英

Pop-Up with ASP.Net Button Click that is not blocked with popup blocker

I currently have an ASP.Net button click event that does a few things (including change session variables) prior to registering a new startup script As is, when a user clicks the button, their pop-up blocker blocks the popup even though it was technically triggered by a user event; I imagine the browser doesn't see it that way.

protected void ContinueButton_Click(object sender, EventArgs e)
{
    if (agreement.Checked)
    {
        string eid = Request.QueryString["eid"];
        Session["TestAgreement"] = "Agreed";
        openNewWindow("Exams/exam.aspx?id=" + courseCode, "height=760, width=1000, status=yes, toolbar=no, menubar=no, location=no, scrollbars=1");
    }          
}
private void openNewWindow(string url, string parameters)
{
    ClientScript.RegisterStartupScript(this.GetType(), "Exam", String.Format("<script>window.open('" + url + "', '', '" + parameters + "');</script>"));
}

AjaxControlToolkit's modal popup works nicely for this sort of thing.

http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ModalPopup/ModalPopup.aspx

its still within the asp.net framework so you still get all your server side goodness, and you can always pop a usercontrol inside of it so that you can treat it as a separate "page"

just remember to keep your cclientidmode on your objects as static or predictable if you want to be able to hit them from your client side.

Do it with javascript. Do not open a new Window, just set a div in front and change its content.

The easiest would be, to use Jquery Dialog:

http://api.jqueryui.com/dialog/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM