Open New Browser Window and AJAX

Last post 10-07-2008 6:41 AM by sri_dotnet. 14 replies.

Sort Posts:

  • Confused [8-)] Open New Browser Window and AJAX

    10-28-2007, 7:35 AM
    • Member
      6 point Member
    • NetSpike
    • Member since 11-24-2006, 3:25 PM
    • Posts 21

    Hi

    I have an Update Panel and inside the Update Panel I have Button.

    The Button's OnClick event has the following code to open a new window with the spesified page:

    protected void Button1_Click(object sender, EventArgs e)
    {

    // Other Code is over here that needs to be done before opening the new browser window with the page.

    Response.Write("<script>");

    Response.Write("window.open('page.html','_blank')");Response.Write("</script>");

    }

     

    When I click the button in the browser, I receive the following error:

    Sys.WebForms.PageRequestManagerParserErrorException:  The message received from the server could not be parsed.  Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server is trace enabled.  Details:  Error parsing near '<script>window.open('.

    How can fix this error?

    Thanks for any help!!!

    Regards
    Edward

  • Re: Open New Browser Window and AJAX

    10-28-2007, 3:35 PM
    Answer
    • All-Star
      25,662 point All-Star
    • Luis Abreu
    • Member since 02-12-2005, 6:22 AM
    • Madeira [Portugal]
    • Posts 5,368
    • TrustedFriends-MVPs

    hello.

    that is correct, you cannot use response.write on a page that uses an updatepanel.  i think that you should do that directly from client code, but if you need to insert code from the server, then take a look at the static registerXXX static methods available on the scriptmanager class...

    --
    Regards,
    Luis Abreu
    email: labreu_at_gmail.com
    EN blog:http://msmvps.com/blogs/luisabreu
  • Re: Open New Browser Window and AJAX

    10-28-2007, 4:20 PM
    Answer
    • Member
      6 point Member
    • NetSpike
    • Member since 11-24-2006, 3:25 PM
    • Posts 21

    Hey

    I'm now using:

    ScriptManager.RegisterStartupScript(this, this.GetType(), "key", "window.open('edward.aspx','_blank');", true);

    In the Button Click event, and it works great!

    Thanks!

    Edward

  • Re: Open New Browser Window and AJAX

    10-28-2007, 4:59 PM
    • Member
      2 point Member
    • oscarthe
    • Member since 10-27-2007, 5:53 PM
    • Posts 2

    I'm trying to open a new window from within a modal popup. I'm not using  an update panel. The contents of the popup is simply html markup passed from a webservice back to a javascript function then inserted into the standard panel. I've tried to open the new window by inserting a link that calls a javascript open.window method but have had no joy. Do you know if there's an alternative method to the one described above? Cheers.

  • Re: Open New Browser Window and AJAX

    01-11-2008, 6:04 PM
    • Member
      2 point Member
    • deuce4
    • Member since 09-07-2007, 4:53 PM
    • Posts 4

    You guys are awesome.  I love it when the person asking the question figures it out AND helps others figure it out too.  Good code JuJu there.

     I had a slight variation on the code in vb. net:

     

    ScriptManager.RegisterStartupScript(Me, Me.GetType(), "key", "window.open('http://www.bigwalls.net','_blank');", True)

     

    thanks again!!!

  • Re: Open New Browser Window and AJAX

    05-30-2008, 4:35 AM
    • Member
      686 point Member
    • danmbuen
    • Member since 10-25-2005, 9:00 AM
    • Bulacan, Philippines
    • Posts 182

     also worked for me thanks! :)

  • Re: Open New Browser Window and AJAX

    07-17-2008, 11:19 AM
    • Member
      258 point Member
    • zoetosis
    • Member since 12-02-2005, 9:28 AM
    • Cheshire, England
    • Posts 112

    Excellent solution.

    I've been looking at ways of doing this all day and this is by far the simplest and most effective solution.

    Many thanks

  • Re: Open New Browser Window and AJAX

    07-23-2008, 5:47 PM
    • All-Star
      17,038 point All-Star
    • guru_sarkar
    • Member since 08-30-2007, 8:00 PM
    • Posts 2,578

    Thanks a lot...worked for me.

  • Re: Open New Browser Window and AJAX

    07-25-2008, 8:04 AM
    • Member
      258 point Member
    • zoetosis
    • Member since 12-02-2005, 9:28 AM
    • Cheshire, England
    • Posts 112

    I've just tried to add the code to a second page and it doesn't open the window.

    The original code that I added continues to work just fine and I can't work out why the window isn't opening.

    The line:

    ScriptManager.RegisterStartupScript(this, this.GetType(), "key", "window.open('PrintPage.aspx','_blank','location=0,toolbar=0,titlebar=0,menubar=0,resizable=1,scrollbars=1,status=1');", true);

    is the same as I used on the other page.

    When stepping through the code the line 'appears' to be executed but I don't get the new window.
    Is there something I could have left off this second form which may not be immediately obvious?

    Any Suggestions gratefully received
  • Re: Open New Browser Window and AJAX

    07-25-2008, 8:18 AM
    • Member
      258 point Member
    • zoetosis
    • Member since 12-02-2005, 9:28 AM
    • Cheshire, England
    • Posts 112

    Problem Resolved:-

    I'd put the button that initiated the print process outside the Update Panel. Once it was moved inside it worked fine

  • Re: Open New Browser Window and AJAX

    08-07-2008, 6:51 AM
    • Member
      258 point Member
    • zoetosis
    • Member since 12-02-2005, 9:28 AM
    • Cheshire, England
    • Posts 112

    Can someone tell me what the proper format is for the URL when the page I want to open is in another folder within my ASP.Net application.

    I can get this to work if the page to be opened is in the same folder as the page that issues the ScriptManager.RegisterStartupScript command.
    However, as I only needed to open a generic page I placed it in it's own folder but I can't get the URL correct.

    I've tried:

    '~/Print/PrintPage.aspx'
    '//Print/PrintPage.aspx'
    '/Print/PrintPage.aspx'
    None of which work.
    Documentation I've searched hasn't helped either 
  • Re: Open New Browser Window and AJAX

    08-07-2008, 7:04 AM
    • Star
      8,667 point Star
    • Pawan_Mishra
    • Member since 03-13-2008, 11:37 AM
    • Bangalore
    • Posts 1,266

     Hi

    Try '../Print/PrintPage.aspx' , hope it may work . 

    Regards
    Pawan Mishra

    Too many eyes doesn't make a good code !!!

    .Net 360°
  • Re: Open New Browser Window and AJAX

    08-07-2008, 8:40 AM
    • Member
      258 point Member
    • zoetosis
    • Member since 12-02-2005, 9:28 AM
    • Cheshire, England
    • Posts 112

    Thanks Pawan, that worked fine.

    Whilst I'm thinking about it is there a way of opening the window so that I don't get the path to the page displayed on the bar at the top of the browser?

     

  • Re: Open New Browser Window and AJAX

    08-07-2008, 8:45 AM
    • Star
      8,667 point Star
    • Pawan_Mishra
    • Member since 03-13-2008, 11:37 AM
    • Bangalore
    • Posts 1,266

    Hi

    The page which you are trying to open , for that page give the title . In code behind in page load you can give page title by something like this :-

    Page.Title = "Sample page";

    otherwise

    in *.aspx page in page directive you can give the title of the page for the Title attribute of page directive tag .

    Regards
    Pawan Mishra

    Too many eyes doesn't make a good code !!!

    .Net 360°
  • Re: Open New Browser Window and AJAX

    10-07-2008, 6:41 AM
    • Member
      2 point Member
    • sri_dotnet
    • Member since 10-07-2008, 6:38 AM
    • Posts 1
    I face an issue when using this. IF popup blocker is enabled then window.open triggers the pop-up blocker message " blah blah blah". IF I choose to allow pop up then I loose the contents in my page and the page reloads. Have anyone come across this issue ?
Page 1 of 1 (15 items)