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. Dynamic Control Events not Fireing

Dynamic Control Events not Fireing

Scheduled Pinned Locked Moved ASP.NET
databasehelpquestion
7 Posts 3 Posters 1 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
    Andre Stroebel
    wrote on last edited by
    #1

    Hi all :) My problem is as follows, I have a ASP Table. Then I add rows/columns in code behind, but one of my columns is a control. I need to see when the Index have changed for specific reasons but the event doesnt fire... Here is my code, something wrong?? //In Page Load TableRow tr = new TableRow(); TableCell tblCell = new TableCell(); RadioButtonList rbL = new RadioButtonList(); rbL.RepeatDirection = RepeatDirection.Horizontal; rbL.SelectedIndexChanged += new EventHandler(rbL_SelectedIndexChanged); rbL.Items.Add("Yes"); rbL.Items.Add("No"); tblCell.Controls.Add(rbL); tr.Cells.Add(tblCell); tblSurvey.Rows.Add(tr); //End of Page Load void rbL_SelectedIndexChanged(object sender, EventArgs e) { //Code here.. }

    J C 3 Replies Last reply
    0
    • A Andre Stroebel

      Hi all :) My problem is as follows, I have a ASP Table. Then I add rows/columns in code behind, but one of my columns is a control. I need to see when the Index have changed for specific reasons but the event doesnt fire... Here is my code, something wrong?? //In Page Load TableRow tr = new TableRow(); TableCell tblCell = new TableCell(); RadioButtonList rbL = new RadioButtonList(); rbL.RepeatDirection = RepeatDirection.Horizontal; rbL.SelectedIndexChanged += new EventHandler(rbL_SelectedIndexChanged); rbL.Items.Add("Yes"); rbL.Items.Add("No"); tblCell.Controls.Add(rbL); tr.Cells.Add(tblCell); tblSurvey.Rows.Add(tr); //End of Page Load void rbL_SelectedIndexChanged(object sender, EventArgs e) { //Code here.. }

      J Offline
      J Offline
      Jesse Squire
      wrote on last edited by
      #2

      Unless I miss my guess, I believe that your issue is caused by a change in the automatic ids assigned to controls during each postback. I believe that if assign an explicit value to the ID property of your RadioButtonList, it will solve your problem. Also, verify that your table has an ID assigned to it, and is being placed in the same container on the page. Hope that helps. :)

      --Jesse

      "... the internet's just a big porn library with some useful articles stuck in." - Rob Rodi

      A 1 Reply Last reply
      0
      • J Jesse Squire

        Unless I miss my guess, I believe that your issue is caused by a change in the automatic ids assigned to controls during each postback. I believe that if assign an explicit value to the ID property of your RadioButtonList, it will solve your problem. Also, verify that your table has an ID assigned to it, and is being placed in the same container on the page. Hope that helps. :)

        --Jesse

        "... the internet's just a big porn library with some useful articles stuck in." - Rob Rodi

        A Offline
        A Offline
        Andre Stroebel
        wrote on last edited by
        #3

        Hey Jesse, thanx for the quick rely! Ok, I assigned the RadioButtonList' ID explicitly now. But it is still not Fireing for some reason :^) I inserted a breakpoint but it never eners the Event Handler..

        J 1 Reply Last reply
        0
        • A Andre Stroebel

          Hey Jesse, thanx for the quick rely! Ok, I assigned the RadioButtonList' ID explicitly now. But it is still not Fireing for some reason :^) I inserted a breakpoint but it never eners the Event Handler..

          J Offline
          J Offline
          Jesse Squire
          wrote on last edited by
          #4

          It appears that we missed setting the RadioButtonList property AutoPostback to true. Without that being set, there will be no postback when the value changes. Hope that helps. :)

          --Jesse

          "... the internet's just a big porn library with some useful articles stuck in." - Rob Rodi

          1 Reply Last reply
          0
          • A Andre Stroebel

            Hi all :) My problem is as follows, I have a ASP Table. Then I add rows/columns in code behind, but one of my columns is a control. I need to see when the Index have changed for specific reasons but the event doesnt fire... Here is my code, something wrong?? //In Page Load TableRow tr = new TableRow(); TableCell tblCell = new TableCell(); RadioButtonList rbL = new RadioButtonList(); rbL.RepeatDirection = RepeatDirection.Horizontal; rbL.SelectedIndexChanged += new EventHandler(rbL_SelectedIndexChanged); rbL.Items.Add("Yes"); rbL.Items.Add("No"); tblCell.Controls.Add(rbL); tr.Cells.Add(tblCell); tblSurvey.Rows.Add(tr); //End of Page Load void rbL_SelectedIndexChanged(object sender, EventArgs e) { //Code here.. }

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

            Your problem is that you need to add controls prior to page_load for their viewstate to be restored. Viewstate is how events are handled. I believe LoadViewState is the place to do this. There are CP articles on this topic.

            Christian Graus Please read this if you don't understand the answer I've given you "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
            • A Andre Stroebel

              Hi all :) My problem is as follows, I have a ASP Table. Then I add rows/columns in code behind, but one of my columns is a control. I need to see when the Index have changed for specific reasons but the event doesnt fire... Here is my code, something wrong?? //In Page Load TableRow tr = new TableRow(); TableCell tblCell = new TableCell(); RadioButtonList rbL = new RadioButtonList(); rbL.RepeatDirection = RepeatDirection.Horizontal; rbL.SelectedIndexChanged += new EventHandler(rbL_SelectedIndexChanged); rbL.Items.Add("Yes"); rbL.Items.Add("No"); tblCell.Controls.Add(rbL); tr.Cells.Add(tblCell); tblSurvey.Rows.Add(tr); //End of Page Load void rbL_SelectedIndexChanged(object sender, EventArgs e) { //Code here.. }

              J Offline
              J Offline
              Jesse Squire
              wrote on last edited by
              #6

              Christian makes a great point that I overlooked. :-O While setting AutoPostBack and assigning an id will get your event to fire, you will not be able to query the value of the radio button list. As he mentions, your control is being created too late in the cycle for it to receive its state. ViewState is restored after the page's Init cycle and before the Load cycle. You may wish to consider creating your controls either in the OnInit method or in an Init event handler.

              --Jesse

              "... the internet's just a big porn library with some useful articles stuck in." - Rob Rodi

              A 1 Reply Last reply
              0
              • J Jesse Squire

                Christian makes a great point that I overlooked. :-O While setting AutoPostBack and assigning an id will get your event to fire, you will not be able to query the value of the radio button list. As he mentions, your control is being created too late in the cycle for it to receive its state. ViewState is restored after the page's Init cycle and before the Load cycle. You may wish to consider creating your controls either in the OnInit method or in an Init event handler.

                --Jesse

                "... the internet's just a big porn library with some useful articles stuck in." - Rob Rodi

                A Offline
                A Offline
                Andre Stroebel
                wrote on last edited by
                #7

                Thanx alot Jesse / Christian!!!!! I now create the coontrols in the Page_Init, this now saves the state and fires me events. :) :) :) :) :) :) :)

                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