阿宽

Nothing is more powerful than habit!
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

asp.net中Response.Redirect方法在新窗口中弹出方法

Posted on 2009-10-30 11:01  宽田  阅读(1483)  评论(0编辑  收藏  举报
一、目的说明:
  页面中有一个Buttn,名称为btnNew。它将弹出一个新增内容的页面。
  页面中有一个gridview用于显示数据。gridview的最后两列是“详细”和“删除”。
  现在要求btnNew弹出新的窗口,用于新增数据。
  GidView中的“详细”列弹出新的窗口,用于查看数据。
  GidView中的“删除”列用于删除当前行的数据。
现在问题来了。
  问题1、用Response.Redirect的方法无法在打开新窗口。 
  问题2、如果使用form中的target='_blank'属性,当单击GridView中的删除时,会出弹出新的窗口。
  问题3、如果将“删除”变成<a href='xxx.aspx' target='_blank'>删除</a> 的形式。无法调用后代代码,除非使用Ajax。

  问题4、如要使用js的window.open()方法。当使用“window.opener.location.href=window.opener.location.href” 刷新父窗口时,不能刷新gridview中的数据。   当使用“window.opener.location.reload();” 刷新父窗口时,每次刷新都弹出让从新发送消息的对话框,让点确定重发消息来刷新页面(后一种方法是网友测试的)。

二、解决方法为:
  1、当单击BtnNew方法时,让form.target='_blank',这样所有链接都会在新窗口中打开。

  2、当单击删除时,先让form.target='_self'。这样就不会弹出新的窗口。

 

三、代码如下:

  1、单击btnNew前让form.target='_blank'。此方法放在load事件中。

    protected void Page_Load(object sender, EventArgs e)
    {
        
try
        {
            
if (!IsPostBack)
            {
                btnNew.Attributes.Add(
"onclick""form.target='_blank'");
            }            
        }
        
catch (Exception error)
        {           
        }
    }

   2、在删除前让先让form.target='_self'代码:此事件放在gridview的RowDataBound事件中。代码:

    protected void gvwList_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        
//隐藏Key
        e.Row.Cells[0].Visible = false;
        
//不显示弹出窗口,并删除提示。
        e.Row.Cells[e.Row.Cells.Count - 1].Attributes["onclick"= "document.forms[0].target='_self'; return confirm('确定删除吗?');";
    }