I am trying to populate a drop down list on partial post back, not sure why it's not working.
this works,
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
populatemyDropDownList();
}
this doesn't work,
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
populatemyDropDownList();
}
Scenario
*I click on button_1 in UpdatePanel_1, which then triggers a partial post back (no page refresh) and tries to populate DropDownList which is in UpdatePanel_2*
when I debug, I can see code behind method is triggering and going through this code but no gain, I think partial post back resets DropDownList ????
using (SqlDataSource sqlds = new SqlDataSource(ConnectionString(), SelectCommand()))
{
drop1.DataSource = sqlds;
drop1.DataTextField = "UserName";
drop1.DataBind();
}
You could use
to check if you're in an asynchronous postback.
However, i would not rely your logic on postbacks(or
!IsPostBack
) andIsInAsyncPostBack
. Instead i would use the correct events. In this case you want to handlebutton_1
's click event to fill theDropDownList
inUpdatePanel2
.Note that you should make
UpdatePanel2
's UpdateModeConditional
. Then you can callUpdatePanel2.Update()
manually after you've filled theDropDownList
.