Posted By

Krummelz on 11/07/11


Tagged

jquery aspnet


Versions (?)

JQuery popup new window from ASP.NET page


 / Published in: JavaScript
 

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.

  1. $(document).ready(function() {
  2.  
  3. //get the current URL
  4. var originalUrl = $('form').attr('action');
  5.  
  6. //change the ASP.NET ViewState value so .NET doesn't break
  7. $('#__VIEWSTATE').attr('name', 'name');
  8.  
  9. //the new URL
  10. var url = 'MyPopup.aspx';
  11.  
  12. //find the form, and change its url
  13. $('form').attr('action', url).attr('target', '_blank');
  14.  
  15. //post the form
  16. $('form').submit();
  17.  
  18. //set it back to the original one
  19. $('form').attr('action', originalUrl).removeAttr('target');
  20.  
  21. //change the ViewState value back to what it was
  22. $('#__VIEWSTATE').attr('name', '__VIEWSTATE');
  23.  
  24. });

Report this snippet  

You need to login to post a comment.