using window.open javascript in asp.net

Discussion in 'ASP .Net' started by Stephen Witter, Mar 4, 2004.

  1. I am currently using response.redirect in a aspx to go to a web page.
    What I want is to open the page in a new window. My dotnet code is as
    follows:

    Dim sFileName as string = "/TempReports/tempReport.pdf"
    response.redirect(sFileName)

    This opens in the same frame and I want to use something like
    window.open so I can force a new page and control the size of the
    window, etc.... One thing I thought about is calling a javascript
    function from within a linkbutton. I don't want to use the
    attributes.add because the link button already has code.

    I have tried:

    Dim scriptString As String = "<script language='javascript'>
    {window.open(" & sFileName & ");} </script>"

    Response.Write(scriptString)

    but the "<script language=javascript></script>" doesn't come across as
    a string in my code, it actually comes across as an actual script tag
    even though it is in quotes.


    I have tried:

    Response.Write("<META HTTP-EQUIV=""REFRESH"" Content=""0;URL=" &
    sFileName & """ target=""_blank"">")

    to at least get it to open in a new window but I can't get it to work.
    Even though I have the target=""_blank"" it still opens in the same
    frame.

    Any suggestions?
     
    Stephen Witter, Mar 4, 2004
    #1
    1. Advertising

  2. Stephen Witter

    George Guest

    I think you have to lose the braces { }, and register the script.

    Dim scriptString As String = "<script language='JavaScript'>
    window.open('/TempReports/tempReport.pdf');</script>"

    RegisterStartupScript("whatever", scriptString)

    I assume it will work if you drop your sFileName var in there, as well. Worth a try, anyway.

    George


    "Stephen Witter" <> wrote in message
    news:...
    > I am currently using response.redirect in a aspx to go to a web page.
    > What I want is to open the page in a new window. My dotnet code is as
    > follows:
    >
    > Dim sFileName as string = "/TempReports/tempReport.pdf"
    > response.redirect(sFileName)
    >
    > This opens in the same frame and I want to use something like
    > window.open so I can force a new page and control the size of the
    > window, etc.... One thing I thought about is calling a javascript
    > function from within a linkbutton. I don't want to use the
    > attributes.add because the link button already has code.
    >
    > I have tried:
    >
    > Dim scriptString As String = "<script language='javascript'>
    > {window.open(" & sFileName & ");} </script>"
    >
    > Response.Write(scriptString)
    >
    > but the "<script language=javascript></script>" doesn't come across as
    > a string in my code, it actually comes across as an actual script tag
    > even though it is in quotes.
    >
    >
    > I have tried:
    >
    > Response.Write("<META HTTP-EQUIV=""REFRESH"" Content=""0;URL=" &
    > sFileName & """ target=""_blank"">")
    >
    > to at least get it to open in a new window but I can't get it to work.
    > Even though I have the target=""_blank"" it still opens in the same
    > frame.
    >
    > Any suggestions?
     
    George, Mar 5, 2004
    #2
    1. Advertising

  3. Thanks for your reply. The questions I posted was a process that was
    a second choice for me because I couldn't do something I wanted to do
    in a web form. As it turns out the reason I couldn't do it the way I
    wanted to had to do with misspelling an event name. The event in
    dotnet was OnSelectedIndexChanged. I was spelling it
    OnSelectedIndexChange.

    Funny, it took me almost three weeks to catch that I didn't have a "d"
    on the end of my event.

    shesh...

    "George" <------@----.---> wrote in message news:<fLT1c.74380$>...
    > I think you have to lose the braces { }, and register the script.
    >
    > Dim scriptString As String = "<script language='JavaScript'>
    > window.open('/TempReports/tempReport.pdf');</script>"
    >
    > RegisterStartupScript("whatever", scriptString)
    >
    > I assume it will work if you drop your sFileName var in there, as well. Worth a try, anyway.
    >
    > George
    >
    >
    > "Stephen Witter" <> wrote in message
    > news:...
    > > I am currently using response.redirect in a aspx to go to a web page.
    > > What I want is to open the page in a new window. My dotnet code is as
    > > follows:
    > >
    > > Dim sFileName as string = "/TempReports/tempReport.pdf"
    > > response.redirect(sFileName)
    > >
    > > This opens in the same frame and I want to use something like
    > > window.open so I can force a new page and control the size of the
    > > window, etc.... One thing I thought about is calling a javascript
    > > function from within a linkbutton. I don't want to use the
    > > attributes.add because the link button already has code.
    > >
    > > I have tried:
    > >
    > > Dim scriptString As String = "<script language='javascript'>
    > > {window.open(" & sFileName & ");} </script>"
    > >
    > > Response.Write(scriptString)
    > >
    > > but the "<script language=javascript></script>" doesn't come across as
    > > a string in my code, it actually comes across as an actual script tag
    > > even though it is in quotes.
    > >
    > >
    > > I have tried:
    > >
    > > Response.Write("<META HTTP-EQUIV=""REFRESH"" Content=""0;URL=" &
    > > sFileName & """ target=""_blank"">")
    > >
    > > to at least get it to open in a new window but I can't get it to work.
    > > Even though I have the target=""_blank"" it still opens in the same
    > > frame.
    > >
    > > Any suggestions?
     
    Stephen Witter, Mar 5, 2004
    #3
  4. Stephen Witter

    George Guest

    Been there. Done that. ;-)


    "Stephen Witter" <> wrote in message
    news:...
    > Thanks for your reply. The questions I posted was a process that was
    > a second choice for me because I couldn't do something I wanted to do
    > in a web form. As it turns out the reason I couldn't do it the way I
    > wanted to had to do with misspelling an event name. The event in
    > dotnet was OnSelectedIndexChanged. I was spelling it
    > OnSelectedIndexChange.
    >
    > Funny, it took me almost three weeks to catch that I didn't have a "d"
    > on the end of my event.
    >
    > shesh...
    >
    > "George" <------@----.---> wrote in message

    news:<fLT1c.74380$>...
    > > I think you have to lose the braces { }, and register the script.
    > >
    > > Dim scriptString As String = "<script language='JavaScript'>
    > > window.open('/TempReports/tempReport.pdf');</script>"
    > >
    > > RegisterStartupScript("whatever", scriptString)
    > >
    > > I assume it will work if you drop your sFileName var in there, as well. Worth a try, anyway.
    > >
    > > George
    > >
    > >
    > > "Stephen Witter" <> wrote in message
    > > news:...
    > > > I am currently using response.redirect in a aspx to go to a web page.
    > > > What I want is to open the page in a new window. My dotnet code is as
    > > > follows:
    > > >
    > > > Dim sFileName as string = "/TempReports/tempReport.pdf"
    > > > response.redirect(sFileName)
    > > >
    > > > This opens in the same frame and I want to use something like
    > > > window.open so I can force a new page and control the size of the
    > > > window, etc.... One thing I thought about is calling a javascript
    > > > function from within a linkbutton. I don't want to use the
    > > > attributes.add because the link button already has code.
    > > >
    > > > I have tried:
    > > >
    > > > Dim scriptString As String = "<script language='javascript'>
    > > > {window.open(" & sFileName & ");} </script>"
    > > >
    > > > Response.Write(scriptString)
    > > >
    > > > but the "<script language=javascript></script>" doesn't come across as
    > > > a string in my code, it actually comes across as an actual script tag
    > > > even though it is in quotes.
    > > >
    > > >
    > > > I have tried:
    > > >
    > > > Response.Write("<META HTTP-EQUIV=""REFRESH"" Content=""0;URL=" &
    > > > sFileName & """ target=""_blank"">")
    > > >
    > > > to at least get it to open in a new window but I can't get it to work.
    > > > Even though I have the target=""_blank"" it still opens in the same
    > > > frame.
    > > >
    > > > Any suggestions?
     
    George, Mar 5, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RJN
    Replies:
    1
    Views:
    8,747
    Patrik Löwendahl [C# MVP]
    Oct 10, 2004
  2. ml
    Replies:
    0
    Views:
    1,456
  3. ml
    Replies:
    2
    Views:
    4,858
    John C. Bollinger
    Nov 30, 2004
  4. PC HUA
    Replies:
    2
    Views:
    422
    PC HUA
    May 19, 2004
  5. IveCal
    Replies:
    0
    Views:
    173
    IveCal
    Apr 2, 2007
Loading...

Share This Page