How to use an asp:button to create a new browser window and output contents to new window

Discussion in 'ASP .Net' started by =?Utf-8?B?Tm92aWNl?=, Jun 9, 2004.

  1. Hi all, as you can see from the subject, I'm try to use an asp:button to create a new browser window and output contents to new window

    But default if I do the
    Response.Write("..."

    The output gets sent directly to the window or frame that the button was contained in - if I was using regular anchor links I could just specify the target - i.e.
    <a href="http://...." target="nameNotInCurrentFrameset">something</a

    Thanks
    Novice
    =?Utf-8?B?Tm92aWNl?=, Jun 9, 2004
    #1
    1. Advertising

  2. You can't do it from service side. Use client-side javascript calls
    showModalDialog(...) or showModalessDialog(...)

    Eliyahu

    "Novice" <6tc1ATqlinkDOTqueensuDOTca> wrote in message
    news:...
    > Hi all, as you can see from the subject, I'm try to use an asp:button to

    create a new browser window and output contents to new window.
    >
    > But default if I do the:
    > Response.Write("...")
    >
    > The output gets sent directly to the window or frame that the button was

    contained in - if I was using regular anchor links I could just specify the
    target - i.e.:
    > <a href="http://...." target="nameNotInCurrentFrameset">something</a>
    >
    > Thanks,
    > Novice
    Eliyahu Goldin, Jun 9, 2004
    #2
    1. Advertising

  3. Indeed you have to do use client-side code, but you actually can generate that code from server-side, al you have to do is append this code to Page.Load event handler of your ASP.NET web form.

    What I do in this code is to generate the actual client side script line by line using a StringBuilder for concatenation, then I have all the script code rendered in the client HTML (immediately below the opening tag of the Page object’s <form runat=â€serverâ€> ) when the page loads using the RegisterClientScriptBlock.

    Then, using the button's Attributes collection, I map the onclick client event of the ASP.NET button to the name of the script I previously generated.

    This will cause you ASP.NET button to respond to the onclick client-side event by opening a new browser window, you can customize the new browser window, in my case i did it like a popup, so that I can append some parameters to the query string.

    Hope this helps,
    Alan Ferrandiz
    MCT;MCDBA,MCSD for .NET
    MSF Practitioner



    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim oStringBuilder As New System.Text.StringBuilder()
    oStringBuilder.Append("<SCRIPT language=""javascript"">")
    oStringBuilder.Append(vbNewLine)
    oStringBuilder.Append(" <!--")
    oStringBuilder.Append(vbNewLine)
    oStringBuilder.Append(" function popup(url) {")
    oStringBuilder.Append(vbNewLine)
    oStringBuilder.Append(" newwindow = window.open(url,'name','height=300,width=450,scrollbars=no');")
    oStringBuilder.Append(vbNewLine)
    oStringBuilder.Append(" if (window.focus) {newwindow.focus()}")
    oStringBuilder.Append(vbNewLine)
    oStringBuilder.Append(" return false;")
    oStringBuilder.Append(vbNewLine)
    oStringBuilder.Append(" }")
    oStringBuilder.Append(vbNewLine)
    oStringBuilder.Append(" //-->")
    oStringBuilder.Append(vbNewLine)
    oStringBuilder.Append("</SCRIPT>")

    Page.RegisterClientScriptBlock("popup", oStringBuilder.ToString)

    Button1.Attributes.Add("onClick", "return popup('popup.aspx?value=somevalue');")

    End Sub





    "Novice" <6tc1ATqlinkDOTqueensuDOTca> escribió en el mensaje news:...
    > Hi all, as you can see from the subject, I'm try to use an asp:button to create a new browser window and output contents to new window.
    >
    > But default if I do the:
    > Response.Write("...")
    >
    > The output gets sent directly to the window or frame that the button was contained in - if I was using regular anchor links I could just specify the target - i.e.:
    > <a href="http://...." target="nameNotInCurrentFrameset">something</a>
    >
    > Thanks,
    > Novice
    Alan Ferrandiz Langley, Jun 9, 2004
    #3
    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. Don Adams
    Replies:
    1
    Views:
    580
    Martin Honnen
    Mar 5, 2004
  2. Tim Reynolds

    asp button on popup is opening new browser window...?

    Tim Reynolds, Nov 9, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    168
    Tim Reynolds
    Nov 9, 2004
  3. Gordon
    Replies:
    3
    Views:
    288
    Steven Burn
    Apr 16, 2004
  4. Kamarulnizam Rahim
    Replies:
    4
    Views:
    203
    Robert Klemme
    Jan 28, 2011
  5. Replies:
    0
    Views:
    177
Loading...

Share This Page