Monday, March 26, 2012

UpdatePanel + JavaScript - window.close()

Hello!

Situation: 2 pages. ASP.NET 2.0, Microsoft Ajax Extension Beta 2, IIS6.

On first page by Click on "Show" button (asp:Button) - worked next Client Java script code - "window.open( 'page2.aspx', '', '' );".

Page2 - contents UpdatePanel and button "Close" (asp:Button) with follow simple Java script code: "self.close();".

If I'm click on "Show" button 3 times and close second page on "Close" button I have persist situation when IE not load second page and don't load any pages in 1 page after second page is closed.

If I'm put "Close" button outside UpdatePanel - all work right.

Thank you,

for any comments.

Igor

I think you have following code:

page1.aspx:
<asp:Button runat="server" ID="btn" OnClientClick="window.open('page2.aspx','','');" Text="Open" />

page2.aspx:
<asp:Button runat="server" ID="btn" OnClientClick="self.close();" Text="Close" /

1. Is there any reason than you are using <asp:Button /> instead of simple <input type="button" /> ?

2. for some control sets asp.net places following onclick code "__doPostBack('btn','')" to <asp:Button />. and you result onclick = "self.close();__doPostBack('btn','')". you can check it viewing page source in browser. (you can use OnClientClick="window.close();return false;//")

3. I always use window.close() instead of self.close();

so try rewrite code like this:

page1.aspx:
<input type="button" onclick="window.open('page2.aspx','',''); return false;" value="Open" />

page2.aspx
<input type="button" onclick="window.close(); return false;" value="Close" />

I think this must work ;)


Thank you!

It's work.

No comments:

Post a Comment