这是情况,我有一个AJAX模式弹出,我的面板里面是两(2)个连接下拉列表。一个是欧洲大陆,另一个是国家。例如,当用户选择亚洲时,各国的下拉应该包含数据。这是我的模态弹出窗口和Panel
的代码 <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>
现在我的问题是,当我的模态弹出窗口加载时,当我选择一个大陆时,国家/地区的下拉列表不会加载。当我向我的ContinentDropDown插入AutoPostBack =“true”时,Modal Pop Up刷新并退出。我花了很长时间调试并知道如何解决这个问题。救命啊!
这是我的代码隐藏
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();
}
答案 0 :(得分:0)
您是否尝试将pnlPopup
面板放在ASP.NET UpdatePanel
控件中?现在,当您的下拉列表执行回发时,它将是部分回发,因为它们都在UpdatePanel
内,并且它应该保持弹出式面板上的可见性。
有关创建和使用UpdatePanel
的详细信息,请查看Introduction to the UpdatePanel Control。
当您将控件置于UpdatePanel
之外时,AutoPostback="true"
会导致完全回发,将弹出式面板“重置”为隐藏,因为这是模式弹出扩展程序的目标控件的默认状态。