Return to Snippet

Revision: 52950
at November 7, 2011 17:55 by Krummelz


Initial Code
$(document).ready(function() {
    
    //get the current URL
    var originalUrl = $('form').attr('action');

    //change the ASP.NET ViewState value so .NET doesn't break
    $('#__VIEWSTATE').attr('name', 'name');

    //the new URL
    var url = 'MyPopup.aspx';

    //find the form, and change its url
    $('form').attr('action', url).attr('target', '_blank');

    //post the form
    $('form').submit();

    //set it back to the original one
    $('form').attr('action', originalUrl).removeAttr('target');

    //change the ViewState value back to what it was
    $('#__VIEWSTATE').attr('name', '__VIEWSTATE');

});

Initial URL

                                

Initial Description
This can be put into a utility class in your ASP.NET project and put onto the page with ScriptManager.RegisterStartupScript(). The script alters the ASP.NET __VIEWSTATE value which somehow validates requests; if you leave it out the popup wont work.

Initial Title
JQuery popup new window from ASP.NET page

Initial Tags
jquery, aspnet

Initial Language
JavaScript