views:

75

answers:

1

I am using below code for javascript window "Yes/No". It is firing twice. Is there any way I can avoid this? Or use any other code?. I need this code behind.

Response.Write("<script language='javascript'> { self.close() }</script>");
+1  A: 

It looks like you're using Response.Write where it would end up at the bottom of the page, like this:

 </html>
 <script language='javascript'> { self.close() }</script>

This will give all sorts of funky behavior, instead use ClientScript.RegisterStartupScript, like this:

ClientScript.RegisterStartupScript(typeof(Page),"close","window.close();",true);

If you were using update panels (which doesn't seem the case from Response.Write()) you would use the similar ScriptManager.RegisterStartupScript() method.

Nick Craver