2011-12-14 52 views
0

我创建了一个多选CheckBoxList的面板,通过PopControl扩展器连接到TextBox。Popextender在提交后关闭面板

我正在使用PopControl扩展器的.commit()方法来显示所选项目。

当我从CheckBox中选择一个项目时,面板关闭,我想选择该项目而不关闭面板。

我在做什么错?当您单击其中一个复选框导致它有AutoPostBack = "true"

标记

<asp:TextBox ID="txtCountry" runat="server" Skinid="longTextbox" AutoPostBack = "false" OnClientItemSelected="passtohidden()" /> 
<asp:Panel ID="pnlLocation" runat="server"> 
    <asp:UpdatePanel runat="server" ID="upLocation"> 
     <ContentTemplate> 
      <asp:CheckBoxList ID="chkLocation" SkinID ="chkColor" runat="server" AutoPostBack = "true" onselectedindexchanged="chkLocation_SelectedIndexChanged" /> 
     </ContentTemplate> 
     <Triggers> 
      <asp:AsyncPostBackTrigger ControlID="txtCountry" EventName="TextChanged" /> 
     </Triggers> 
    </asp:UpdatePanel> 
</asp:Panel> 
<asp:PopupControlExtender ID="Panel1_PopupControlExtender" runat="server" Enabled="True" Position="Bottom" PopupControlID = "pnlLocation" TargetControlID="txtCountry" /> 

代码背后

protected void chkLocation_SelectedIndexChanged(object sender, EventArgs e) 
{ 
    string strSelected = ""; 

    foreach (ListItem l in chkLocation.Items) 
    { 
     if (l.Selected) 
     { 
      strSelected += l.Text + " ,"; 
     } 
    } 

    //txtCountry.Text = strSelected; 

    Panel1_PopupControlExtender.Commit(strSelected); 
} 

回答

0

面板关闭。

为了能够选择多个复选框,只需将AutoPostBack设置为false,然后在CheckBoxList旁边创建一个按钮,在选中所有必需的复选框后,点击该按钮执行异步回发。为此,您还需要在按钮上设置UseSubmitBehavior="false"

<asp:TextBox ID="txtCountry" runat="server" Skinid="longTextbox" AutoPostBack = "false" OnClientItemSelected="passtohidden()" /> 
<asp:Panel ID="pnlLocation" runat="server"> 
    <asp:UpdatePanel runat="server" ID="upLocation"> 
     <ContentTemplate> 
      <asp:CheckBoxList ID="chkLocation" SkinID ="chkColor" runat="server" AutoPostBack = "false" onselectedindexchanged="chkLocation_SelectedIndexChanged" /> 
      <asp:Button runat="server" ID="submitButton" Text="Ok" UseSubmitBehavior="false" /> 
     </ContentTemplate> 
     <Triggers> 
      <asp:AsyncPostBackTrigger ControlID="txtCountry" EventName="TextChanged" /> 
     </Triggers> 
    </asp:UpdatePanel> 
</asp:Panel> 
<asp:PopupControlExtender ID="Panel1_PopupControlExtender" runat="server" Enabled="True" Position="Bottom" PopupControlID = "pnlLocation" TargetControlID="txtCountry" />