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. Multiple events on post-back

Multiple events on post-back

Scheduled Pinned Locked Moved ASP.NET
helptutorialquestion
10 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.
  • A Offline
    A Offline
    AumSingh
    wrote on last edited by
    #1

    I am facing a unique problem (looks unique to me at least). I have a dropdown whose auto-postback is enabled. User can select a value from the dropdown to go to another page. But when the user comes back to original page by clicking the back button on the browser and clicks any button then on the post-back caused by the button, first the "SelectedIndexChanged" event handler of that dropdown is called then the "Click" event handler of this button is called. Hope I have explained the problem clearly. Can anyone tell me what's going wrong and how to solve the issue?

    A C Y 3 Replies Last reply
    0
    • A AumSingh

      I am facing a unique problem (looks unique to me at least). I have a dropdown whose auto-postback is enabled. User can select a value from the dropdown to go to another page. But when the user comes back to original page by clicking the back button on the browser and clicks any button then on the post-back caused by the button, first the "SelectedIndexChanged" event handler of that dropdown is called then the "Click" event handler of this button is called. Hope I have explained the problem clearly. Can anyone tell me what's going wrong and how to solve the issue?

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      Just put the code that you have written for redirect to different page of Dropdownlist SelectedIndexChanged.

      cheers, Abhijit CodeProject MVP

      A 1 Reply Last reply
      0
      • A AumSingh

        I am facing a unique problem (looks unique to me at least). I have a dropdown whose auto-postback is enabled. User can select a value from the dropdown to go to another page. But when the user comes back to original page by clicking the back button on the browser and clicks any button then on the post-back caused by the button, first the "SelectedIndexChanged" event handler of that dropdown is called then the "Click" event handler of this button is called. Hope I have explained the problem clearly. Can anyone tell me what's going wrong and how to solve the issue?

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        om pr wrote:

        Can anyone tell me what's going wrong and how to solve the issue?

        I suspect that what is happening is that when you go back the browser remembers the state of the controls when you originally left the page and sets them to those values. However, this time the value change for the drop down does not trigger a post back. When you press the button the postback is triggered. The server then compares what is in the viewstate with what the controls now look like and raise events for any changes. Because it sees two changes (the drop down and the button click) those events are raised. A possible route to solving the issue is to turn off the viewstate (which also means you won't get change events, although you will still get button click events) and detect the drop down change yourself rather than rely on ASP.NET.

        *Developer Day Scotland - Free community conference Delegate Registration Open

        A 1 Reply Last reply
        0
        • A Abhijit Jana

          Just put the code that you have written for redirect to different page of Dropdownlist SelectedIndexChanged.

          cheers, Abhijit CodeProject MVP

          A Offline
          A Offline
          AumSingh
          wrote on last edited by
          #4

          I did the same but it is not working......looks like the browser is remembering the previous state of the page and so is causing the previous event to be raised in addition the present event..... I think I have to take help of javascript. Thank for the reply

          A 1 Reply Last reply
          0
          • C Colin Angus Mackay

            om pr wrote:

            Can anyone tell me what's going wrong and how to solve the issue?

            I suspect that what is happening is that when you go back the browser remembers the state of the controls when you originally left the page and sets them to those values. However, this time the value change for the drop down does not trigger a post back. When you press the button the postback is triggered. The server then compares what is in the viewstate with what the controls now look like and raise events for any changes. Because it sees two changes (the drop down and the button click) those events are raised. A possible route to solving the issue is to turn off the viewstate (which also means you won't get change events, although you will still get button click events) and detect the drop down change yourself rather than rely on ASP.NET.

            *Developer Day Scotland - Free community conference Delegate Registration Open

            A Offline
            A Offline
            AumSingh
            wrote on last edited by
            #5

            Thanks for the reply Colin, I tried all possible options including disabling the viewstate as suggested by you but it all failed. I just managed to solve the issue with the help of javascript. Instead of sending the user to the next page via Response.Redirect on the index change of the dropdown, I am now doing the same with the help of simple javascript i.e. window.location.href. Thanks again for the reply, appreciate it!

            C 1 Reply Last reply
            0
            • A AumSingh

              Thanks for the reply Colin, I tried all possible options including disabling the viewstate as suggested by you but it all failed. I just managed to solve the issue with the help of javascript. Instead of sending the user to the next page via Response.Redirect on the index change of the dropdown, I am now doing the same with the help of simple javascript i.e. window.location.href. Thanks again for the reply, appreciate it!

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #6

              What happens if the user has disabled javascript?

              *Developer Day Scotland - Free community conference Delegate Registration Open

              A 1 Reply Last reply
              0
              • C Colin Angus Mackay

                What happens if the user has disabled javascript?

                *Developer Day Scotland - Free community conference Delegate Registration Open

                A Offline
                A Offline
                AumSingh
                wrote on last edited by
                #7

                I our case this will not happen because whole site is javascript dependent. If it is disabled then nothing will work and moreover the site is for Intranet use and user of this site will not have the flexibility to turn the javascript setting of the browser on or off at will. But this question still remains. What if the site were for general public on the Internet? In that case what could be the solution if even javascript could not solve it? Any idea!!

                1 Reply Last reply
                0
                • A AumSingh

                  I did the same but it is not working......looks like the browser is remembering the previous state of the page and so is causing the previous event to be raised in addition the present event..... I think I have to take help of javascript. Thank for the reply

                  A Offline
                  A Offline
                  Abhijit Jana
                  wrote on last edited by
                  #8

                  om pr wrote:

                  I did the same but it is not working....

                  :doh: But I didn't suggested you to do any thing. I have just asked you to put those selected index change code.

                  cheers, Abhijit CodeProject MVP

                  A 1 Reply Last reply
                  0
                  • A Abhijit Jana

                    om pr wrote:

                    I did the same but it is not working....

                    :doh: But I didn't suggested you to do any thing. I have just asked you to put those selected index change code.

                    cheers, Abhijit CodeProject MVP

                    A Offline
                    A Offline
                    AumSingh
                    wrote on last edited by
                    #9

                    Can you be a bit more elaborate. I did not understand what you want to suggest! :(

                    1 Reply Last reply
                    0
                    • A AumSingh

                      I am facing a unique problem (looks unique to me at least). I have a dropdown whose auto-postback is enabled. User can select a value from the dropdown to go to another page. But when the user comes back to original page by clicking the back button on the browser and clicks any button then on the post-back caused by the button, first the "SelectedIndexChanged" event handler of that dropdown is called then the "Click" event handler of this button is called. Hope I have explained the problem clearly. Can anyone tell me what's going wrong and how to solve the issue?

                      Y Offline
                      Y Offline
                      Yusuf
                      wrote on last edited by
                      #10

                      Is this happening only one one machine? Can you reproduce it on another machine. Today, I spent 30 minutes on non-issue with my boss's machine. The browser had old cached copy and clearing the cache *fixed* the issue.

                      Yusuf Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]

                      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