DropDown List on web user control is empty after postback

264 views Asked by At

There is a drop down list on the web user control (.ascx). I am binding the DropDown list control on aspx code behind page. I have tried binding it in Load , PreLoad events but its just empty after postback. I have tried the enable view state option but no luck.

I have a method in web user control for binding dropdown list and i am calling it from the main aspx code which is using this web user control .

.ascx

    public void FillDropDownList(string divisionCode, Int32 webEvevntID)
{
    DataSet dsDist = GetData(divisionCode, webEvevntID);
    ddlDist.DataSource = dsDist.Tables(0);
    ddlDist.DataTextField = "DistributorName";
    ddlDist.DataValueField = "DistNum";
    ddlDist.DataBind();
}

.aspx c#

private void Order_PreRender(object sender, EventArgs e)
{
    FillDropDownList();
}
2

There are 2 answers

0
Ajoe On

Do this in pageload of user control

private void Order_PageLoad(object sender, EventArgs e)
{
  if(!IsPostBack())
    FillDropDownList();
 }
0
Muhammad Aftab On

As @AA said, try below

.aspx c#

private void Order_PageLoad(object sender, EventArgs e)
{
  if(!IsPostBack())
    FillDropDownList();
 }

or you can try this:

.ascx

private void On_PageLoad(object sender, EventArgs e)
    {
      if(!IsPostBack())
        FillDropDownList();
     }