Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Open a popup window from.net code behind

Open a popup window from.net code behind

Scheduled Pinned Locked Moved ASP.NET
csharpcomdesigntoolsquestion
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gunnar66
    wrote on last edited by
    #1

    Hi I am trying to open a new window from a button in my aspx side. This works, but I have to push the button 2 times before it open. Any idea? Public Shared Sub OpenPopUp(ByVal opener As System.Web.UI.WebControls.WebControl, ByVal PagePath As String) Dim clientScript As String 'Building the client script- window.open clientScript = "window.open('" & PagePath & "')" 'register the script to the clientside click event of the opener control opener.Attributes.Add("onClick", clientScript) End Sub Sub Button1_Click(sender As Object, e As EventArgs) OpenPopup(Button1,"http://www.google.com") End Sub

    S 1 Reply Last reply
    0
    • G gunnar66

      Hi I am trying to open a new window from a button in my aspx side. This works, but I have to push the button 2 times before it open. Any idea? Public Shared Sub OpenPopUp(ByVal opener As System.Web.UI.WebControls.WebControl, ByVal PagePath As String) Dim clientScript As String 'Building the client script- window.open clientScript = "window.open('" & PagePath & "')" 'register the script to the clientside click event of the opener control opener.Attributes.Add("onClick", clientScript) End Sub Sub Button1_Click(sender As Object, e As EventArgs) OpenPopup(Button1,"http://www.google.com") End Sub

      S Offline
      S Offline
      Stefan Troschuetz
      wrote on last edited by
      #2

      The first click on the Button results in the execution of the OpenPopUp method, which then registers the script to the client side click event. As your site is already posted back to the server, the client script wasn't part of the site and wasn't executed after the first click. Cause it's included in the response for the first click, the second has the wanted result. To avoid the need for two clicks, move the code of your OpenPopUp method to the Load event of the Page or something similar, so that the client script is always part of your page.


      www.troschuetz.de

      G 1 Reply Last reply
      0
      • S Stefan Troschuetz

        The first click on the Button results in the execution of the OpenPopUp method, which then registers the script to the client side click event. As your site is already posted back to the server, the client script wasn't part of the site and wasn't executed after the first click. Cause it's included in the response for the first click, the second has the wanted result. To avoid the need for two clicks, move the code of your OpenPopUp method to the Load event of the Page or something similar, so that the client script is always part of your page.


        www.troschuetz.de

        G Offline
        G Offline
        gunnar66
        wrote on last edited by
        #3

        Thanks But in the button its not always the same .html page that I want to open. When I push the button I first have to lookpup in a database to find out which html page that I need to open. So its not possisble to move this to the Load event, because I not know the name of the .html page. How can I do this?

        S 1 Reply Last reply
        0
        • G gunnar66

          Thanks But in the button its not always the same .html page that I want to open. When I push the button I first have to lookpup in a database to find out which html page that I need to open. So its not possisble to move this to the Load event, because I not know the name of the .html page. How can I do this?

          S Offline
          S Offline
          Stefan Troschuetz
          wrote on last edited by
          #4

          What criteria determines which page gets opened when you click the button? Otherwise maybe there is some "javascript" event like load or similar, which allows you to open the popup after postback of the first click.? So that you don't register the script to the click event of your button, but to the other.


          www.troschuetz.de

          G 1 Reply Last reply
          0
          • S Stefan Troschuetz

            What criteria determines which page gets opened when you click the button? Otherwise maybe there is some "javascript" event like load or similar, which allows you to open the popup after postback of the first click.? So that you don't register the script to the click event of your button, but to the other.


            www.troschuetz.de

            G Offline
            G Offline
            gunnar66
            wrote on last edited by
            #5

            Hi there I am not that good in asp.net programming. But what I need to do is this. A user is filling out som criteria and then I send this value to a access database. A VB.exe program is checking this value and give me respond back. The information I get from the VB.exe prog is the .html page I need to open. So if there is a other way to do this thats fine, but all methods I find to open a new window, you have to know the name of the html page. Thanks

            S 1 Reply Last reply
            0
            • G gunnar66

              Hi there I am not that good in asp.net programming. But what I need to do is this. A user is filling out som criteria and then I send this value to a access database. A VB.exe program is checking this value and give me respond back. The information I get from the VB.exe prog is the .html page I need to open. So if there is a other way to do this thats fine, but all methods I find to open a new window, you have to know the name of the html page. Thanks

              S Offline
              S Offline
              Stefan Troschuetz
              wrote on last edited by
              #6

              Ok, I think there are two possible ways. 1. You'll catch the change of the criteria and adjust the client script that's registered to the Button. But as this solution requires additional postbacks (for every change) and I don't know exactly what your users have to fill out, I guess this isn't such a good solution. 2. You still catch the Click event of your button and register the client script. Not to the Button click, but to the onload event of your page. I'm not sure how to do this, but I think you'll find out. Anyway the page that gets posted back must have a body tag similar to the following one:


              www.troschuetz.de

              G 1 Reply Last reply
              0
              • S Stefan Troschuetz

                Ok, I think there are two possible ways. 1. You'll catch the change of the criteria and adjust the client script that's registered to the Button. But as this solution requires additional postbacks (for every change) and I don't know exactly what your users have to fill out, I guess this isn't such a good solution. 2. You still catch the Click event of your button and register the client script. Not to the Button click, but to the onload event of your page. I'm not sure how to do this, but I think you'll find out. Anyway the page that gets posted back must have a body tag similar to the following one:


                www.troschuetz.de

                G Offline
                G Offline
                gunnar66
                wrote on last edited by
                #7

                Hi 1. Is it possible to change the client script? The user is filling out start and stop time. A exe program generates a html page for me. 2. I don't know how too do this, but i try to find out. Thanks

                S 1 Reply Last reply
                0
                • G gunnar66

                  Hi 1. Is it possible to change the client script? The user is filling out start and stop time. A exe program generates a html page for me. 2. I don't know how too do this, but i try to find out. Thanks

                  S Offline
                  S Offline
                  Stefan Troschuetz
                  wrote on last edited by
                  #8

                  It sounds practicable, but I'm too unexperienced with javascript or similar things to say how.


                  www.troschuetz.de

                  G 1 Reply Last reply
                  0
                  • S Stefan Troschuetz

                    It sounds practicable, but I'm too unexperienced with javascript or similar things to say how.


                    www.troschuetz.de

                    G Offline
                    G Offline
                    gunnar66
                    wrote on last edited by
                    #9

                    Ok Thanks for your help.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups