C# ASP下拉列表回发在Chrome和IE中丢失会话状态,但firefox工作正常

C# ASP下拉列表回发在Chrome和IE中丢失会话状态,但firefox工作正常,c#,asp.net,C#,Asp.net,我的母版页上有一个ddl,该ddl设置为自动回发以根据其选择检索数据。列表中的值是CustomerID,它们已设置为会话变量,一旦有人选择了其中一个,代码将查看会话[“selectedCustomer”]并填充相应的字段。现在我遇到的问题是,当自动回发在Chrome或IE上进行时,它填充字段,然后选择的客户被设置回默认值,即“请选择客户”,后面没有任何值。在firefox中,回发后会填充字段,然后下拉列表会保留在所选客户上 protected void ddlSelectedCustom

我的母版页上有一个ddl,该ddl设置为自动回发以根据其选择检索数据。列表中的值是CustomerID,它们已设置为会话变量,一旦有人选择了其中一个,代码将查看会话[“selectedCustomer”]并填充相应的字段。现在我遇到的问题是,当自动回发在Chrome或IE上进行时,它填充字段,然后选择的客户被设置回默认值,即“请选择客户”,后面没有任何值。在firefox中,回发后会填充字段,然后下拉列表会保留在所选客户上

    protected void ddlSelectedCustomer_SelectedIndexChanged(object sender, EventArgs e)
    {
        CustomerSelected();

        Response.AppendHeader("Refresh", "0; URL=" + this.ResolveUrl("~/AcesSetup/storefront.aspx"));
        try
        {
            ViewState["SelectedAccordionIndex"] = ((AjaxControlToolkit.Accordion)FindControl("MyAccordion")).SelectedIndex;
        }
        catch (Exception ex)
        { }
    }
这是我的ddl的selectedChanged事件

    private void CustomerSelected()
    {

        //clear the session variable
        Session.Remove("selectedCustomer");

        //user selected customer
        if (ddlSelectedCustomer.SelectedIndex != -1)
        {
            Session["selectedCustomer"] = ddlSelectedCustomer.SelectedValue;
        }

    }

    private void fillCustomers()
    {

        //save the value of the current selection to reselect later if still exists
        string origSelectedItem = ddlSelectedCustomer.SelectedValue;

        //check what role the user is in
        string usersRole = Roles.GetRolesForUser(Membership.GetUser().UserName)[0];

        MembershipUser user = Membership.GetUser();

        switch (usersRole)
        {
            case "SalesRep":
                ddlSelectedCustomer.DataSource = DAL.Util.getSalesRepCustomers((Guid)user.ProviderUserKey);
                ddlSelectedCustomer.DataBind();

                break;
            case "BasicUser":
            case "Customer":
                ddlSelectedCustomer.DataSource = DAL.Util.getCustomersListForUser((Guid)user.ProviderUserKey);
                ddlSelectedCustomer.DataBind();

                break;
            case "Admin":
            case "SuperAdmin":
                ddlSelectedCustomer.DataSource = DAL.Util.getAllCustomersList(); 
                ddlSelectedCustomer.DataBind();
                break;
            default:
                break;
        }

        //if user had a company selected, reselect it if it exists
        if (origSelectedItem != string.Empty)
            ddlSelectedCustomer.SelectedValue = origSelectedItem;
        else if (ddlSelectedCustomer.Items.Count == 1)
        {
            //if only one item in the list, select it
            ddlSelectedCustomer.Items[0].Selected = true;
        }
这是填充下拉列表的内容。另外,当Firefox发回时,整个页面不会重新加载,使用Chrome或IE时,整个页面将闪烁白色并重新加载。。在我看来,这似乎与此有关。因为在Firefox上,我的手风琴的viewstate功能与预期的一样,但在Chrome或IE上也没有

如果您有任何帮助,我将不胜感激,如果有什么我可以澄清,或任何代码,我可以提供我会尽我所能更新一切

多谢各位

 protected void ContentPlaceHolder1_Load(object sender, EventArgs e)
        {
            if (Session["selectedCustomer"] != null)
            {
                ddlSelectedCustomer.SelectedValue = Session["selectedCustomer"].ToString();
            }
        }




你不会错过这个环节,您只需清除所选内容。因此,请尝试通过存储会话设置所选值来处理
ContentPlaceHolder
Load
事件。

为什么代码会附加
Refresh
响应标题?没有它,我无法获得要普及的信息。是否重定向到同一页面或不同的页面页为什么不使用
Response.Redirect
方法呢?同一个页面,下拉列表在我的母版页上,而在Firefox上,刷新,刷新母版页上的嵌套页面,对于chrome和IE,它会刷新整个页面。这很有意义,我并不是100%认为会话丢失,因为默认选择的值设置为null,这就是它被告知要查看的值,因为ddl返回到它。我应用了你建议的方法,但现在它不是加载结果,而是每次设置断点时都将其设置为默认值,并查看是否有什么方法可以阻止此操作。谢谢你的回复。
 <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server" OnLoad="ContentPlaceHolder1_Load">
 </asp:ContentPlaceHolder>