Visuaalselt näeb välja nii, et klikid kugugi ja avaneb ekraaninkattega aken.
Kasutame ModalPopupExtender-it mille ees näitab UserControli sisu
<asp:Label runat="server" ID="HForModal" style="display: none" />
<asp:Panel runat="server" ID="P1" ScrollBars="Auto" Wrap="true" Width="80%" CssClass="modalPopup">
<asp:Button ID="ButtonModalClose" ClientIDMode="Static" runat="server" CausesValidation="False" CssClass="actionButton" Text="<%$ Resources:resource, ButtonClose %>" />
<uc3:BoxNeibhours ID="BoxNeibhours1" runat="server" kuupaevNahtav="false"/>
</asp:Panel>
<ajaxToolkit:ModalPopupExtender runat="server" ID="ModalPopupExtender1" X="120" BackgroundCssClass="moduleBackground" TargetControlID="HForModal" OkControlID="ButtonModalClose"
CancelControlID="ButtonModalClose" PopupControlID="P1" BehaviorID="HForModal">
</ajaxToolkit:ModalPopupExtender>
Kui nüüd see ekraanikattega aken avaneb, tahaks teda ESC klahviga sulgeda, aga ei kao ta ühtegi
CancelControlID ei mõju ESC klahvile, ehk JavaSript appi
if (!Page.ClientScript.IsClientScriptIncludeRegistered("onKeyEsc"))
{
string url = ResolveClientUrl("~/Scripts/SulgeModal.js");
Page.ClientScript.RegisterClientScriptInclude("onKeyEsc", url);
}
JavaSript ise SulgeModal.js selline
function pageLoad(sender, args) {
if (!args.get_isPartialLoad()) {
// adding handler to the document's keydown event
$addHandler(document, "keydown", onKeyDown);
}
}
function onKeyDown(e) {
if (e && e.keyCode == Sys.UI.Key.esc) {
// if the key pressed is the escape key, then close the dialog
//alert("close");
var bname = document.getElementById("ButtonModalClose"); //ClientIDMode="Static"
if (bname !== null)
{
bname.click();
}
//PageMethods.SulgeAken(); //ei tööta
}
}
Tähele tuleb panna seda kohta JavaScriptis
document.getElementById("ButtonModalClose")
vastav Button tuleb ClientIDMode="Static" defineerida
asp:Button ID="ButtonModalClose" ClientIDMode="Static"