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