人生是一场不能存盘的RPG,我只能尽量多搞几个Screenshot

February 3, 2007

如何在关闭ModalDialog时避免打开新的IE窗口

Filed under: ASP.NET

很多时候,asp.net程序需要弹出一个Modal Dialg来收集用户的输入,这个Modal Dialg会有”OK”,”Cancel”两个button,使用javascript关闭dialog,但是有一些猫腻会导致在Modal Dialg中点击了”OK”或”Cancel”后,不但dialog不关闭反而打开一个新的IE.

原因就在于如果点击button导致了页面的提交,就会出现上述情况,如果这个Modal Dialg所对应的aspx页面是用vs自动生成,asp:button缺省就会提交页面,
此时如果在页面的<head></head>中添加<base target=_self></base>,就可以防止打开新的IE,但故事并没有结束,如果不幸在页面的form中,指定了
<form id=”form1″ runat=”server” target=”_self”>
用上述方法也阻止不了新的IE弹出.此时,需要使用更强大的手段:及在page load时指定form1的target:
javaScript:
function handleOnLoad()
{
window.name = ‘dialognew’ + Number(new Date()).toString();
document.dialognew.target = window.name;
}
form:
<form id=”dialognew” method=”post” target=”_self” runat=”server”>

Comments »

The URI to TrackBack this entry is: http://recordsome.blogsome.com/2007/02/03/p213/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.






















Get free blog up and running in minutes with Blogsome
Theme designed by Hadley Wickham