简体   繁体   中英

DropDown List on web user control is empty after postback

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();
}

Do this in pageload of user control

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

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();
     }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM