在web应用程序中,[asp.net]我正在使用模态popu控件,它工作正常,但在模态弹出关闭按钮[取消按钮]事件,我写了一个代码重定向到另一个页面,但它不是重定向[可能事件没有解雇],你能帮助我吗?
<asp:Panel ID ="slideshow1" runat ="server" >
<asp:GridView ID ="grd" runat ="server" ></asp:GridView>
<asp:Button ID ="btnClos" runat ="server" onclick="btnClos_Click" Text ="X close" />
</asp:Panel>
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID ="btn"
CancelControlID="btnClos" PopupControlID="slideshow1" BackgroundCssClass="modalBackground">
</asp:ModalPopupExtender>
<asp:Button ID ="btn" runat ="server" style="display:none;" />
答案 0 :(得分:1)
我怀疑ModalPopupExtender可能没有传播关闭按钮的提交,因为它是扩展器的取消按钮。有几种选择:
您可以使用java-script API为ModalPopupExtender隐藏它,而不是将其用作CancelControlID
参数。例如,
<asp:Panel ID ="slideshow1" runat ="server" >
<asp:GridView ID ="grd" runat ="server" ></asp:GridView>
<asp:Button ID ="btnClos" runat ="server" onClick="btnClos_Click" OnClientClick="return DoClose();" Text ="X close" />
</asp:Panel>
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID ="btn"
PopupControlID="slideshow1" BackgroundCssClass="modalBackground">
</asp:ModalPopupExtender>
<script type="text/javascript">
function DoClose() {
// close the modal popup
$('<%= ModalPopupExtender1.ClientID %>').hide();
// return true so that submit will happen
return true;
}
</script>
当您想要重定向到另一个页面时,更好的选择是简单地重定向到不同的页面,而不是使用服务器端重定向。
<asp:Panel ID ="slideshow1" runat ="server" >
<asp:GridView ID ="grd" runat ="server" ></asp:GridView>
<asp:Button ID ="btnClos" runat ="server" OnClientClick="return DoClose();" Text ="X close" />
</asp:Panel>
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID ="btn"
CancelControlID="btnClos" PopupControlID="slideshow1" BackgroundCssClass="modalBackground">
</asp:ModalPopupExtender>
<script type="text/javascript">
function DoClose() {
// redirect
window.location.href = '/ToAnotherPage.aspx?q=some';
// return false so that submit will be blocked
return false;
}
</script>