Urgent!!! Dropdown list load event handler not firing in a connected web part
This is driving me nuts. I have a web part A which provides a person code to web part B to show the schedule of the person. Both web parts are using drop down lists. Connection between two web parts and sending the person code is done ,np in that. If I move the code inside of the drpDownSchedule_Load to RenderContents event everything works fine except the fact when I choose something from the drop down list in web part B and page gets post back, I lose the view state (which I think is another issue). so I put everything in the load event with the hope to check for the post back myself,but now dropdown list in web part B is showing nothing. I guess there is a timing issue from when I invoke the person code from web part A and render the controls (using BLL and DAL) in web part B.
Here is the code for Web part B:
protected string _selectedPersonCode = string.Empty;
protected DropDownList _drpDownSchedule;
protected ISchool _PersonProvider = null;
protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
{
base.RenderContents(writer);
}
protected override void OnPreRender(EventArgs e)
{
if (this._personProvider != null)
{
this._selectedPersonCode = this._personProvider.PersonCode;
}
}
[aspnetwebpars.ConnectionConsumer("Person Code")]
public void GetConnectedProviderInterface(IPerson connectionProvider)
{
this._personProvider = connectionProvider;
}
protected override void CreateChildControls()
{
//Drop Down List
_drpDownSchedule = new DropDownList();
_drpDownSchedule.Load += new EventHandler(drpDownSchedule_Load);
_drpDownSchedule.EnableViewState = true;
this.Controls.Add(_drpDownSchedule);
}
void drpDownSchedule_Load(object sender, EventArgs e)
{
try
{
//To handle the post back
if (_drpDownSchedule.Items.Count ==0 && !_selectedSchoolCode.Equals(string.Empty))
{
ScheduleBLL sshBLL = new ScheduleBLL();
DataTable sshDT = (DataTable)sshBLL.GetSchedule(_selectedPersonCode);
_drpDownSchedule.Items.Add(new ListItem("Choose a date"));
foreach (DataRow dtRow in sshDT.Rows)
{
_drpDownSchedule.Items.Add(new ListItem(dtRow[0].ToString()));
}
}
_drpDownSchedule.AutoPostBack = true;
}
catch
{
_drpDownSchedule.Items.Add(new ListItem(Constants.errorSchedule));
}
}
}
}
Please help. Thanks a lot

