ASP.NET GridView中鏈結打開模式窗口,當模式窗口關閉時,刷新父頁.

本文介绍如何在ASP.NET中使用JavaScript打开模式窗口,并在关闭时刷新父页面的方法。包括使用showModelessDialog函数打开窗口、在GridViewRowDataBound事件中添加链接、设置防止缓存的元标签、在Body中添加关闭时执行的JS代码以及触发父页按钮点击事件来实现刷新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 ASP.NET打開模式窗口,當模式窗口關閉時,刷新父頁.

1.使用Javascript: showModelessDialog打開模式窗口

JS代碼:

function showDialog(url, width, height)
{
   showModelessDialog(url, window, 'dialogWidth:' + width + 'px;dialogHeight:' + height + 'px;center:yes;status:no;scroll:yes;help:no');
}

 

2.在GridView RowDataBound事件添加Link代碼

  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
          if (e.Row.RowType == DataControlRowType.DataRow)
        {
            ID = e.Row.Cells[1].Text.ToString().Replace(" ", "").Trim();

            if (ID.Length > 0)
            {

               //添加DT以免緩存影響
                string JS = "View.aspx?ID=" + ID + "&DT=" + DateTime.Now.ToString("yyyyMMddHHmmss");
                e.Row.Cells[2].Text = "<a href=/"javascript:/" onclick=/"javascript:showDialog('" + JS + "',800,590);/">I</a>";
                e.Row.Cells[2].ToolTip = "Open By ID";
            }
        }
    }

 

3.在模式窗口Head中添加清除緩存代碼

    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Cache-Control" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
    <base target="_self" />

 

4.Body添加關閉模式窗口時執行JS代碼,執行父頁Button事件

body style="margin: 0px" onunload="ref();"

function ref()
{
  if(window.dialogArguments != null)
  {
    //window.dialogArguments.location.reload(true);
    //dialogArguments.location.replace(dialogArguments.location);
    dialogArguments.document.getElementById("btnQuery").click();
    //window.close();
    }
}

 

5.父頁Button click事件

   protected void btnQuery_Click(object sender, EventArgs e)
    {
        try
        {
            Bind();
        }
        catch (Exception ex)
        {

        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值