2

我的母版页上有一个 ddl,它设置为自动回发以根据他们的选择检索数据。列表中的值是客户 ID,它们已设置为会话变量,一旦有人选择了哪一个,代码就会查看 session["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,我的手风琴的视图状态就像它应该的那样工作,但同样不能使用 Chrome 或 IE。

如果您有任何帮助,我将不胜感激,如果有任何我可以清理的内容,或者我可以提供的任何代码片段,我会尽力更新所有内容。

谢谢你。

4

1 回答 1

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

 <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server" OnLoad="ContentPlaceHolder1_Load">
 </asp:ContentPlaceHolder>

您不会丢失会话,您只需清除选择。所以尝试通过存储会话设置所选值来处理Load您的事件。ContentPlaceHolder

于 2012-05-15T16:21:38.220 回答