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
  1. Home
  2. Web Development
  3. ASP.NET
  4. Close form after buttonclick

Close form after buttonclick

Scheduled Pinned Locked Moved ASP.NET
csharpjavascriptquestion
5 Posts 3 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.
  • J Offline
    J Offline
    JohnQuar1
    wrote on last edited by
    #1

    Hello, I am trying to close a form after a button click event, but I need it to run some code first. I know about OnClientClick="javaScript:window.close(); return false;" and that successfully closes the window, but I need to be able to run some code behind in C# before that executes. I currently have this for my button: It asks if I want to close the window, but never gets to the onclick event. Does anyone have any ideas? Thanks for your time. JM

    John Michael

    N T 2 Replies Last reply
    0
    • J JohnQuar1

      Hello, I am trying to close a form after a button click event, but I need it to run some code first. I know about OnClientClick="javaScript:window.close(); return false;" and that successfully closes the window, but I need to be able to run some code behind in C# before that executes. I currently have this for my button: It asks if I want to close the window, but never gets to the onclick event. Does anyone have any ideas? Thanks for your time. JM

      John Michael

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      A common approach for this is using AJAX to make the server call prior to closing the window


      only two letters away from being an asset

      J 1 Reply Last reply
      0
      • N Not Active

        A common approach for this is using AJAX to make the server call prior to closing the window


        only two letters away from being an asset

        J Offline
        J Offline
        JohnQuar1
        wrote on last edited by
        #3

        If you've got the time, could you give me a quick example on how to do this, or where I can find an example? I havent really used AJAX much. Thanks! BTW, The code behind is in C#.

        John Michael

        N 1 Reply Last reply
        0
        • J JohnQuar1

          If you've got the time, could you give me a quick example on how to do this, or where I can find an example? I havent really used AJAX much. Thanks! BTW, The code behind is in C#.

          John Michael

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          If you haven't used AJAX then it would be pointless to give code you wouldn't understand. Read up on it, then come back and ask if you don't understand.


          only two letters away from being an asset

          1 Reply Last reply
          0
          • J JohnQuar1

            Hello, I am trying to close a form after a button click event, but I need it to run some code first. I know about OnClientClick="javaScript:window.close(); return false;" and that successfully closes the window, but I need to be able to run some code behind in C# before that executes. I currently have this for my button: It asks if I want to close the window, but never gets to the onclick event. Does anyone have any ideas? Thanks for your time. JM

            John Michael

            T Offline
            T Offline
            Tiger456
            wrote on last edited by
            #5

            I would suggest you to follow the approach explained by jhon. if you are not familiar with AJAX then you can follow this general approach like write javascript code from server side after postback <asp:Button ID="btnVDistro" runat="server" Font-Bold="True" onclick="btnVDistro_Click" Text="Use Validated" /> protected void btnVDistro_Click(object sender, EventArgs e) { // Add your code here this.ClientScript.RegisterStartupScript(this.GetType(), "close", "javaScript:window.close(); return false;, true); }

            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