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. Form unload

Form unload

Scheduled Pinned Locked Moved ASP.NET
question
11 Posts 4 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.
  • P ps srinivasan

    Hello frnd I Declared one global variable.if i open the webform1 i want to set the variable true.(so i wrote the code in form load varname=true).if i am going the webform1 to webform2 i want to set that variable false.in which event i want to write the code?(i wrote the code varname=false in form_unload but before moving other form that code executed)

    N Offline
    N Offline
    N a v a n e e t h
    wrote on last edited by
    #2

    ps.srinivasan wrote:

    I Declared one global variable

    How you declared this ? in Global.asax ? I don't think it's a good solution and in which scenarion you require this ?

    ps.srinivasan wrote:

    if i am going the webform1 to webform2 i want to set that variable false.in which event i want to write the code?

    How you are going from one page to other ? Using a Response.Redirect() ? then set the value just before this line. There is no event fired when you move from one page to other using normal hyperlinks. You need to hook a javascript function on body unload event and using an AJAX call set the variable value to false.

    ps.srinivasan wrote:

    (i wrote the code varname=false in form_unload but before moving other form that code executed)

    Yes, when page requests, it will load the page and call unload. See the ASP.NET page lifecycle.

    All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

    P 1 Reply Last reply
    0
    • P ps srinivasan

      Hello frnd I Declared one global variable.if i open the webform1 i want to set the variable true.(so i wrote the code in form load varname=true).if i am going the webform1 to webform2 i want to set that variable false.in which event i want to write the code?(i wrote the code varname=false in form_unload but before moving other form that code executed)

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #3

      How are you maintaining a global variable ? Do you think that's a good idea ? What if two people are using your site and one is one form1, and one is on form2 ? What are you trying to achieve ?

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      1 Reply Last reply
      0
      • P ps srinivasan

        Hello frnd I Declared one global variable.if i open the webform1 i want to set the variable true.(so i wrote the code in form load varname=true).if i am going the webform1 to webform2 i want to set that variable false.in which event i want to write the code?(i wrote the code varname=false in form_unload but before moving other form that code executed)

        M Offline
        M Offline
        Michael Sync
        wrote on last edited by
        #4

        ps.srinivasan wrote:

        I Declared one global variable.

        Don't declare the global variable.. You should use "Session" or "Cache". For example: Assign "True" to session in WebForm1. Session["myvalue"] = "True" Set "False" this in Webform2. Session["myvalue"] = "False"

        ps.srinivasan wrote:

        in which event i want to write the code?

        You should write this in From_load of Webform2. hope it helps.

        Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) "Please vote to let me (and others) know if this answer helped you or not. A 5 vote tells people that your question has been answered successfully and that I've pitched it at just the right level. Thanks."

        N 1 Reply Last reply
        0
        • M Michael Sync

          ps.srinivasan wrote:

          I Declared one global variable.

          Don't declare the global variable.. You should use "Session" or "Cache". For example: Assign "True" to session in WebForm1. Session["myvalue"] = "True" Set "False" this in Webform2. Session["myvalue"] = "False"

          ps.srinivasan wrote:

          in which event i want to write the code?

          You should write this in From_load of Webform2. hope it helps.

          Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) "Please vote to let me (and others) know if this answer helped you or not. A 5 vote tells people that your question has been answered successfully and that I've pitched it at just the right level. Thanks."

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #5

          Michael Sync wrote:

          You should write this in From_load of Webform2.

          It would be better if referrer also checked to ensure it comes from webform1. Else if anyone directly took webform2, value will be set to false.

          All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

          M 1 Reply Last reply
          0
          • N N a v a n e e t h

            Michael Sync wrote:

            You should write this in From_load of Webform2.

            It would be better if referrer also checked to ensure it comes from webform1. Else if anyone directly took webform2, value will be set to false.

            All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

            M Offline
            M Offline
            Michael Sync
            wrote on last edited by
            #6

            N a v a n e e t h wrote:

            It would be better if referrer also checked to ensure it comes from webform1

            Yeah. I agree..

            Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) "Please vote to let me (and others) know if this answer helped you or not. A 5 vote tells people that your question has been answered successfully and that I've pitched it at just the right level. Thanks."

            P 1 Reply Last reply
            0
            • N N a v a n e e t h

              ps.srinivasan wrote:

              I Declared one global variable

              How you declared this ? in Global.asax ? I don't think it's a good solution and in which scenarion you require this ?

              ps.srinivasan wrote:

              if i am going the webform1 to webform2 i want to set that variable false.in which event i want to write the code?

              How you are going from one page to other ? Using a Response.Redirect() ? then set the value just before this line. There is no event fired when you move from one page to other using normal hyperlinks. You need to hook a javascript function on body unload event and using an AJAX call set the variable value to false.

              ps.srinivasan wrote:

              (i wrote the code varname=false in form_unload but before moving other form that code executed)

              Yes, when page requests, it will load the page and call unload. See the ASP.NET page lifecycle.

              All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

              P Offline
              P Offline
              ps srinivasan
              wrote on last edited by
              #7

              frnd my requirement is simple,if any one open one form i don't want to allow other person open that same form,how to write code for this scenario?

              N 1 Reply Last reply
              0
              • M Michael Sync

                N a v a n e e t h wrote:

                It would be better if referrer also checked to ensure it comes from webform1

                Yeah. I agree..

                Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) "Please vote to let me (and others) know if this answer helped you or not. A 5 vote tells people that your question has been answered successfully and that I've pitched it at just the right level. Thanks."

                P Offline
                P Offline
                ps srinivasan
                wrote on last edited by
                #8

                rnd my requirement is simple,if any one open one form i don't want to allow other person open that same form,how to write code for this scenario?

                C 1 Reply Last reply
                0
                • P ps srinivasan

                  rnd my requirement is simple,if any one open one form i don't want to allow other person open that same form,how to write code for this scenario?

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #9

                  This is a bizarre requirement for a web app. Your problem is, you cannot know if the first person has left the page. The best way to handle this is to store what pages are 'in use' in the database, because you also need to store the time/date they became in use, and impliment a timeout so that the user loses the page after a while. Otherwise, I can browse to your site ( and I assume I'd be one of only 2-3 people worldwide doing so, for your requirement to not make the site useless ), turn off my PC and your site is broken.

                  Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                  M 1 Reply Last reply
                  0
                  • P ps srinivasan

                    frnd my requirement is simple,if any one open one form i don't want to allow other person open that same form,how to write code for this scenario?

                    N Offline
                    N Offline
                    N a v a n e e t h
                    wrote on last edited by
                    #10

                    ps.srinivasan wrote:

                    frnd my requirement is simple,if any one open one form i don't want to allow other person open that same form

                    :confused: Hope you are speaking about web applications only ! AFAIK, there are not much efficient methods to satisfy this. You can make use of application variables/a database flag indicates somebody opened the page. But big question is how you will reset the value when he finished his visit ? You should rely on some sort of javascript which works on unload. But what will happen if JS is disabled on client's machine ? Your flag status will be still active which prevents further users to the page. So it's not a good solution. Why do you need to implement this ? If you are planning to implement any of the methods I suggested above, make sure you have a time-out mechanism which updates the flag/application variable to the initial stage.

                    All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

                    1 Reply Last reply
                    0
                    • C Christian Graus

                      This is a bizarre requirement for a web app. Your problem is, you cannot know if the first person has left the page. The best way to handle this is to store what pages are 'in use' in the database, because you also need to store the time/date they became in use, and impliment a timeout so that the user loses the page after a while. Otherwise, I can browse to your site ( and I assume I'd be one of only 2-3 people worldwide doing so, for your requirement to not make the site useless ), turn off my PC and your site is broken.

                      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                      M Offline
                      M Offline
                      Michael Sync
                      wrote on last edited by
                      #11

                      I would like to add a few things that might work for you... I think that Session State is based on the user, right? - As Christ said, you should store the pageid and status "in use" in the database. - If you move to other page then change the pageid. - Check whether a particular page is in-use or not in every page_load. - Use "Session" in your page. (you wanna say that you have nothing to store in the Session variable? anyway, use it.. otherwise, you won't get "Session_End".. ) - Delete the record ("pageid" and "in use") in Session_End event. - Don't forget to set "Inproc" in web.config.. I think that it might work.. but it is better if you can change your requirement..

                      Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) "Please vote to let me (and others) know if this answer helped you or not. A 5 vote tells people that your question has been answered successfully and that I've pitched it at just the right level. Thanks."

                      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