开发者

How close Html window when click asp.net button?

I have asp.net button "OK" in html popup window. I after my logic done how close that popup window it self?

<asp:Button Id="btnOK" runat="server"  AccessKey="<%$Resources:
wss,multipages_okbutton_accesskey%>开发者_C百科" 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"

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. I do this with a PlaceHolder and a small script:

<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:

protected void btnOK_Click(Object sender, EventArgs e) {
  bool success = processPage();
  close_script.Visible = success;
}


That requires some 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. It will be dumbed down, but still function. Take a look at this article:

http://accessify.com/features/tutorials/the-perfect-popup/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜