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

[2583 byte] By [RayCan] at [2008-1-1]
# 1

I have found out more things, but still unable to solve the problem:

I am getting the PersonCode in OnPreRender and then using it in CreateChildControl and Load Event of the dropdown list which are basically raied *BEFORE* OnPreRender which now makes sense to me. _selectedPersonCode is empty in Load Event of the dropdown and that;s why I thought the load event is not fired.

Now the question is , where should I put my code in OnPreRender ? I put the code in CreateChildControls and it does not work, I put it in load event and still no luck. What's is the use of connectable web parts if you cannot pass its data to any control in your web part?

Any help is appreciated...

Thanks

RayCan at 2007-9-7 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...
# 2
Same problem. Have you found a solution?
Migee at 2007-9-7 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...
# 3

Yeap , I put an EnsureChildControls() in Provider connection point just before it returns anything.

It is all timing issue man.Let me know if it does not help

RayCan at 2007-9-7 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...
# 4

Cool, never came to mind

Actually I solved the problem in a different way, just moved around everything to fit the timing.

Thanks, good to know

-mike

Migee at 2007-9-7 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...
# 5
Where did you put it exactly ?

I can still not make my TreeView rendering correctly.

Thanks in advance.

obrlk at 2007-9-7 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...

SharePoint Products and Technologies

Site Classified