2013-07-16 79 views
0

這裏是情況,我有一個AJAX模式彈出,在我的面板裏面是兩(2)個連接的下拉列表。一個是歐洲大陸,另一個是國家。其中一個例子就是用戶選擇亞洲時,國家的下降應該包含數據。這裏是我的代碼爲模態彈出,面板Modal彈出AJAX退出時刷新

<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」時,模式彈出窗口會刷新並退出。我花了很長時間調試並知道如何解決這個問題。幫幫我!

這裏是我的代碼隱藏

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

你試過把pnlPopup面板內的ASP.NET UpdatePanel控制的?現在,當您的下拉列表進行回發時,它將是部分回傳,因爲它們都在UpdatePanel之內,並且應該保留彈出式面板上的可見性。有關創建和使用UpdatePanel的更多信息,請參閱Introduction to the UpdatePanel Control

當您將控件放在UpdatePanel以外時,AutoPostback="true"會導致完全回發,將彈出式面板「重置」爲隱藏狀態,因爲這是模式彈出式擴展程序目標控件的默認狀態。

+0

我會把UpdatePanel INSIDE面板? – user1954418

+0

我該怎麼做? – user1954418

+0

問題,我將把AsyncPostBackTrigger放在哪裏?/ – user1954418