C# 即使使用Page.IsPostback,也会在回发时再次删除下拉列表绑定数据

C# 即使使用Page.IsPostback,也会在回发时再次删除下拉列表绑定数据,c#,asp.net,C#,Asp.net,我需要一个列出所有商店的下拉列表。单击时需要获取所选值,但会发生回发,即使在我检查Page.IsPostback时,它也始终为空,因为没有数据 这是我的密码 ============================================= 这是我的aspx文件 我所做的是,我在单击时隐藏一个div,并显示另一个div和所有调查问题,提交时,我需要获取具有dropdownlist的上一个div的值 请帮帮我,因为我觉得很难 谢谢大家。首先,在ASPX中的AsyncPostBackTrig

我需要一个列出所有商店的下拉列表。单击时需要获取所选值,但会发生回发,即使在我检查Page.IsPostback时,它也始终为空,因为没有数据

这是我的密码

=============================================

这是我的aspx文件 我所做的是,我在单击时隐藏一个div,并显示另一个div和所有调查问题,提交时,我需要获取具有dropdownlist的上一个div的值

请帮帮我,因为我觉得很难


谢谢大家。

首先,在ASPX中的
AsyncPostBackTrigger
中指定
DropDownList

<Triggers>
    <asp:AsyncPostBackTrigger ControlID="dropdownlist" EventName="SelectedIndexChanged" />
</Triggers>

启用页面&DropDownlist
viewState
&然后重试

视图状态使服务器控件能够跨HTTP请求维护其状态。如果满足以下所有条件,则启用控件的视图状态:

  • 页面的EnableViewState属性设置为true
  • 控件的EnableViewState属性设置为true
  • 控件的ViewStateMode属性设置为Enabled或Enabled 继承已启用的设置

在control/page init中加载数据(不要检查IsPostBack标志),而不是pageLoad

@patel.milanb call BindAllStores();在PageInit中,您认为是因为我隐藏了一个div,然后显示了另一个div,所以值在回发之间丢失了吗
protected void Page_Load(object sender, EventArgs e)
            {
                        if (!Page.IsPostBack)
                                    BindAllStores();
            }




  protected void emailJoinButton_Click(object sender, EventArgs e)
            {
                        Session["FavStore"] = Stores.SelectedItem.ToString(); --> this is where i am storing the selected value.

                        if (Page.IsValid)
                        {
                                    if (competitionInfo.Visible == true)
                                    {
                                                LoadSurvey();
                                                competitionInfo.Visible = false;
                                                competitionSurvey.Visible = true;
                                    }
                        }
            }


public void  BindAllStores()
            {
                        Stores.AppendDataBoundItems = true;    
                        Stores.Items.Add(new ListItem("--- Choose one of our stroes --- ", "0"));


                        Stores.DataSource = AllStores;
                        Stores.DataTextField = "DisplayName";
                        Stores.DataValueField = "NAME";
                        Stores.DataBind();
            }
<Triggers>
    <asp:AsyncPostBackTrigger ControlID="dropdownlist" EventName="SelectedIndexChanged" />
</Triggers>
protected void Page_Load(object sender, EventArgs e) 
{
    if (!ScriptManager.GetCurrent(Page).IsInAsyncPostBack) 
    {
        BindAllStores();
    }
}