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. Easy User Control Postback Question

Easy User Control Postback Question

Scheduled Pinned Locked Moved ASP.NET
question
5 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.
  • J Offline
    J Offline
    Jason Pease
    wrote on last edited by
    #1

    I created a simple User Control that consists of a few DropDownLists and Labels for a user to select a specific hour and minute. The control loads and functions in the page correctly, but I'm not able to get it's value on postback. The control is used in the EditItemTemplate of a DataGrid and in the DataGrid_UpdateCommand event I'm trying to get the value the user selected. I perform a FindControl like this. DataGrid dg = (DataGrid)source; int editItemIndex = dg.EditItemIndex; DataGridItem dataGridItem= dg.Items[ editItemIndex ]; MyUserControl myUserControl = (MyUserControl) dataGridItem.FindControl( "myUserControl" ); However, when I try to access the properties of the user control, they are always the initialized values, not the ones the user selected. Does anyone see what I'm doing wrong here? Thanks, Jason

    V 1 Reply Last reply
    0
    • J Jason Pease

      I created a simple User Control that consists of a few DropDownLists and Labels for a user to select a specific hour and minute. The control loads and functions in the page correctly, but I'm not able to get it's value on postback. The control is used in the EditItemTemplate of a DataGrid and in the DataGrid_UpdateCommand event I'm trying to get the value the user selected. I perform a FindControl like this. DataGrid dg = (DataGrid)source; int editItemIndex = dg.EditItemIndex; DataGridItem dataGridItem= dg.Items[ editItemIndex ]; MyUserControl myUserControl = (MyUserControl) dataGridItem.FindControl( "myUserControl" ); However, when I try to access the properties of the user control, they are always the initialized values, not the ones the user selected. Does anyone see what I'm doing wrong here? Thanks, Jason

      V Offline
      V Offline
      V 0
      wrote on last edited by
      #2

      is EnableViewState set to true for the controls? "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix

      J 1 Reply Last reply
      0
      • V V 0

        is EnableViewState set to true for the controls? "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix

        J Offline
        J Offline
        Jason Pease
        wrote on last edited by
        #3

        I hadn't touched the EnableViewState because it's supposed to default to true, but even after explicitly setting it to true it still does not work correctly.

        V 1 Reply Last reply
        0
        • J Jason Pease

          I hadn't touched the EnableViewState because it's supposed to default to true, but even after explicitly setting it to true it still does not work correctly.

          V Offline
          V Offline
          V 0
          wrote on last edited by
          #4

          Do you reload the combos after postback? if so try to do this: int tempindex = combo.SelectIndex; //Reload the combo's combo.SelectedIndex = tempindex; good luck. "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix

          J 1 Reply Last reply
          0
          • V V 0

            Do you reload the combos after postback? if so try to do this: int tempindex = combo.SelectIndex; //Reload the combo's combo.SelectedIndex = tempindex; good luck. "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix

            J Offline
            J Offline
            Jason Pease
            wrote on last edited by
            #5

            Thanks for the tip! That was my problem. The only change I made was that if the combos already have an element I skip the loading process. In this case this is acceptable because the content is static (0-23 and 0-59). Thanks again for the 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