[英]How close Html window when click asp.net button?
I have asp.net button "OK" in html popup window. 我在html弹出窗口中有asp.net按钮“确定”。 I after my logic done how close that popup window it self? 在逻辑完成之后,我自己如何关闭该弹出窗口?
<asp:Button Id="btnOK" runat="server" AccessKey="<%$Resources:
wss,multipages_okbutton_accesskey%>" Width="70px" Text="<%$Resources:wss,
multipages_okbutton_text%>" OnClick="btnOK_Click" />
<asp:Button ID="btnOK" runat="server" OnClientClick="window.close(); return false;" Text="Close" />
All correct but there is another way if you want close the window in your code: 都正确,但是如果要关闭代码中的窗口,则还有另一种方法:
Suppose that the button ID is "ContineButton" and the click event handler name is "ContineButton_Click" 假设按钮ID为“ ContineButton”,单击事件处理程序名称为“ ContineButton_Click”
protected void ContineButton_Click(object sender, EventArgs e)
{
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "window.close()", true);
}
If there is a chance that your server side code may fail, and you need to keep the popup open to correct errors, the OnClientClick trick won't help. 如果您的服务器端代码可能会失败,并且您需要使弹出窗口保持打开状态以纠正错误,则OnClientClick技巧将无济于事。 I do this with a PlaceHolder and a small script: 我使用PlaceHolder和一个小脚本来执行此操作:
<asp:PlaceHolder id="close_script" runat="server">
<script>window.close();</script>
</asp:PlaceHolder>
Then, in the button handler, set the Visible property of the PlaceHolder to close the popup (or leave it open: 然后,在按钮处理程序中,设置PlaceHolder的Visible属性以关闭弹出窗口(或将其保持打开状态:
protected void btnOK_Click(Object sender, EventArgs e) {
bool success = processPage();
close_script.Visible = success;
}
That requires some javascript. 那需要一些JavaScript。 Change your button markup to this: 将您的按钮标记更改为此:
<asp:Button Id="btnOK" runat="server" AccessKey="<%$Resources:
wss,multipages_okbutton_accesskey%>" Width="70px" Text="<%$Resources:wss,
multipages_okbutton_text%>" OnClick="btnOK_Click" OnClientClick="javascript:window.close(); return false;" />
There are other things to consider here - an accessible site will work without JavaScript including opening and closing a popup window. 这里还有其他需要考虑的事情-一个可访问的站点无需JavaScript就可以工作,包括打开和关闭弹出窗口。 It will be dumbed down, but still function. 它会变笨,但仍然可以运行。 Take a look at this article: 看一下这篇文章:
http://accessify.com/features/tutorials/the-perfect-popup/ http://accessify.com/features/tutorials/the-perfect-popup/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.