Dropdown binding and postbacks - ASP.NET
- by DotnetDude
I have a rather complex page. The ASPX page loads a user control which in turn loads a child User control.
Parent Control
protected override void OnInit(EventArgs e)
{
//Loads child control
}
In the child user control, I use custom control that inherits from System.Web.UI.HtmlControls.HtmlSelect
ASCX:
<cust:CustDropDownList id="ctlDdl" runat="server"/>
ASCX.CS
protected void Page_Load(object sender, EventArgs e)
{
//Binds CtlDdl here
}
When the user clicks on the Save button, the controls get user controls get dynamically reloaded, but Iose the value the user has selected in the dropdown. I run into the chicken and egg problem here.
I think I need to bind the ctlDdl only on if its not a postback, but that results in the dropdown not getting populated.
If I bind it everytime, then i lose user's selection
EDIT:
Can someone respond to my comment to Jonathan's answer? Thanks