0

情况就是这样,我弹出了一个 AJAX 模式,在我的面板内是两个 (2) 连接的下拉列表。一个是针对大陆的,另一个是针对国家的。一个例子是当用户选择亚洲时,国家的下拉菜单里面应该有数据。这是我的模式弹出和面板代码

  <asp:ModalPopupExtender ID="Modalpopupextender1" runat="server" TargetControlID="ShowPopUpButton"
        PopupControlID="pnlpopup" CancelControlID="CancelButton" BackgroundCssClass="modalBackground">
     </asp:ModalPopupExtender>

  <asp:Panel ID="pnlpopup" runat="server" BackColor="White" Height="269px" Width="400px"
        OnLoad="pnlpopup_Load">
    <tr>
                <td align="right">
                    Continent:
                </td>
                <td>
                    <asp:DropDownList ID="ContinentDownList" runat="server" 
                        onselectedindexchanged="ContinentDropDownList_SelectedIndexChanged" AutoPostBack="true">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td align="right">
                    Country:
                </td>
                <td>
                    <asp:DropDownList ID="CountryDropDownList" runat="server">
                    </asp:DropDownList>
                </td>
            </tr>
      </asp:Panel>

现在我的问题是,当我的模式弹出加载时,当我选择一个大陆时,国家的下拉菜单不会加载。当我将 AutoPostBack="true" 插入 ContinentDropDown 时,模态弹出窗口会刷新并退出。我花了很长时间调试并知道如何解决这个问题。帮助!

这是我的代码隐藏

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            LoadContinent();
            LoadCountry();
        }
    }

  public void LoadContinent()
    {
        using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {

            using (SqlCommand com = new SqlCommand("Reader.usp_LoadContinentDropDownList", con))
            {

               com.CommandType = CommandType.StoredProcedure;
                con.Open();
                try
                {

                   SqlDataReader dr = com.ExecuteReader();
                   OwnerGroupDropDownList.DataSource = dr;
                    OwnerGroupDropDownList.DataTextField = "fld_Description";
                    OwnerGroupDropDownList.DataValueField = "fld_ContinentID";

                    ContinentDropDownList.DataBind();
                }
                catch (SqlException)
                {
                    Response.Write("<script>alert('The database has encountered an error. Please try again')</script>");                    }
                catch (Exception)
                {
                    Response.Write("<script>alert('The database has encountered an error. Please try again')</script>");                    }
            }

        }
        LoadContinentDropDownList.Items.Insert(0, new ListItem("<Select Person Group>", "0")); 
    }


         public void LoadCountry()
    {
        using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {

            using (SqlCommand com = new SqlCommand("Reader.usp_LoadCountryDropDownList", con))
            {


                com.CommandType = CommandType.StoredProcedure;
                com.Parameters.Add(new SqlParameter("@fld_ContinentId", SqlDbType.Int));
                com.Parameters["@fld_ContinentId"].Value = ContinentDropDownList.SelectedValue;
                con.Open();

                try
                {

                    SqlDataReader dr = com.ExecuteReader();
                    OwnerDropDownList.DataSource = dr;
                    OwnerDropDownList.DataTextField = "fld_Description";
                    OwnerDropDownList.DataValueField = "fld_CountryID";

                    CountryDownList.DataBind();
                }
                catch (SqlException)
                {
                    Response.Write("<script>alert('The database has encountered an error. Please try again')</script>");                    }
                catch (Exception)
                {
                   Response.Write("<script>alert('The database has encountered an error. Please try again')</script>");                    }
            }
        }
         CountryDropDownList.Items.Insert(0, new ListItem("<Select Person>", "0")); 
    }

      protected void ContinentDropDownList_SelectedIndexChanged(object sender, EventArgs e)
    {
        LoadContinent();
        LoadCountry();
    }
4

1 回答 1

0

您是否尝试过将pnlPopup面板放在 ASP.NETUpdatePanel控件中?现在,当您的下拉列表进行回发时,这将是部分回发,因为它们都在一个内,UpdatePanel并且应该保持弹出面板上的可见性。

查看UpdatePanel 控件简介,了解有关创建和使用UpdatePanel.

当您将控件放在 之外时UpdatePanel,会AutoPostback="true"导致完整的回发,它将弹出面板“重置”为隐藏,因为这是模式弹出扩展器的目标控件的默认状态。

于 2013-07-16T01:58:43.253 回答