Open New Browser Window and AJAX

Last post 08-07-2008 8:45 AM by Pawan_Mishra. 13 replies.

Sort Posts:

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

    10-28-2007, 7:35 AM
    • Loading...
    • NetSpike
    • Joined on 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
    • Loading...
    • Luis Abreu
    • Joined on 02-12-2005, 6:22 AM
    • Madeira [Portugal]
    • Posts 5,220
    • 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
    PT blog: http://weblogs.pontonetpt.com/luisabreu
    EN blog:http://msmvps.com/blogs/luisabreu
    http://www.pontonetpt.com
    http://weblogs.pontonetpt.com/
  • Re: Open New Browser Window and AJAX

    10-28-2007, 4:20 PM
    Answer
    • Loading...
    • NetSpike
    • Joined on 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
    • Loading...
    • oscarthe
    • Joined on 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
    • Loading...
    • deuce4
    • Joined on 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
    • Loading...
    • danmbuen
    • Joined on 10-25-2005, 9:00 AM
    • Bulacan, Philippines
    • Posts 178

     also worked for me thanks! :)

  • Re: Open New Browser Window and AJAX

    07-17-2008, 11:19 AM
    • Loading...
    • zoetosis
    • Joined on 12-02-2005, 9:28 AM
    • Cheshire, England
    • Posts 100

    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

    Thanks a lot...worked for me.

    /GuruBhai
  • Re: Open New Browser Window and AJAX

    07-25-2008, 8:04 AM
    • Loading...
    • zoetosis
    • Joined on 12-02-2005, 9:28 AM
    • Cheshire, England
    • Posts 100

    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
    • Loading...
    • zoetosis
    • Joined on 12-02-2005, 9:28 AM
    • Cheshire, England
    • Posts 100

    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
    • Loading...
    • zoetosis
    • Joined on 12-02-2005, 9:28 AM
    • Cheshire, England
    • Posts 100

    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
    • Loading...
    • Pawan_Mishra
    • Joined on 03-13-2008, 7:37 AM
    • Bangalore
    • Posts 221

     Hi

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

    Regards

    Pawan Mishra


    "Mark the post as answered if it solves your query"
  • Re: Open New Browser Window and AJAX

    08-07-2008, 8:40 AM
    • Loading...
    • zoetosis
    • Joined on 12-02-2005, 9:28 AM
    • Cheshire, England
    • Posts 100

    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
    • Loading...
    • Pawan_Mishra
    • Joined on 03-13-2008, 7:37 AM
    • Bangalore
    • Posts 221

    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


    "Mark the post as answered if it solves your query"
Page 1 of 1 (14 items)
Microsoft Communities