c# - Dropdown.SelectedIndex doesnt have the correct value in the Page_Load event, but has the correct value in the Render event -
i have aspnet dropdown list in usercontrol. usercontrol gets loaded webform. there submit button on page too. on postback selecteditem not show right value in page_load handler show right value in pre-render , render handlers. under impression viewstate set before page_load.
you're re-data-binding dropdown list between pre_render , page_load. event says, pre_render lets stuff before of controls on page have been rendered. once page rendered (before page_load) it's data-binding dropdown list , erasing selected value.
the easiest way around data-bind dropdown list in code when needs bound, when page first loaded , not on post back.
if (!ispostback) { //do of data binding here databind(); }
Comments
Post a Comment