對此我還是比較新的,並試圖找到答案,所以希望我不會重複這一點。與PopupControlExtender一起使用onCheckedChanged,並希望在取消選中時防止彈出
我使用的是ASP.NET,並有一個複選框控件,它在更改時使用onCheckedChanged方法調出一個彈出框。這個彈出框中有一些信息,並有一個「關閉」按鈕,它可以成功關閉彈出窗口。
我想要的是防止出現彈出如果複選框未選中。我目前有onCheckedChanged調用後面的代碼,如果未檢查控件,取消擴展程序調用的代碼,但彈出窗口很快出現在關閉之前。我怎樣才能防止它呢?
這是適當的頁面代碼:
<div class="row" id="divDDMandate" runat="server">
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:CheckBox ID="chkDDMandate" Width="20px" Visible="true" runat="server" AutoPostBack="true"
OnCheckedChanged="clientchkDDMandateChanged(this);" on />
<asp:Literal ID="ltlDDMandate" runat="server">Direct Debit Mandate (by post)</asp:Literal>
<asp:PopupControlExtender ID="chkDDMandate_PopupControlExtender" runat="server"
DynamicServicePath="" Enabled="true" PopupControlID="PanelDDMandateDownload"
TargetControlID="chkDDMandate"
Position="Bottom" OffsetX="-20" OffsetY="10" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
...這是背後的方法我的代碼:
protected void chkDDMandateChanged(object sender, EventArgs e)
{
//Cancel the panel if unchecking
if ((!chkDDMandate.Checked) && chkDDMandate_PopupControlExtender.Enabled)
{
chkDDMandate_PopupControlExtender.Cancel();
}
}
我會感謝任何幫助。
乾杯
謝謝Yuriy,這讓我更加接近!我新的它需要一個事件處理程序,但我是新來的JavaScript。現在的問題是彈出窗口被完全禁用,直到下一次頁面刷新。我檢查/取消選中,處理程序第一次運行後沒有更多事情發生。 – chopper1400 2012-07-12 09:17:56
嘗試將焦點移出複選框(即單擊頁面上的任意位置)。我相信當控件獲得焦點時,彈出式控件將顯示彈出框。 – 2012-07-12 14:43:48