【问题标题】:close child aspx page if gridview index is changed on parent page如果在父页面上更改了 gridview 索引,则关闭子 aspx 页面
【发布时间】:2011-11-17 20:01:25
【问题描述】:

我有一个父页面和子页面,都是 aspx。一切正常,但现在我想关闭子页面,如果用户离开子弹出页面并返回父页面并单击其他内容,例如 Gridview 的页面索引。如果用户转到另一个应用程序或其他位置,我无法关闭弹出子页面,我只想在父页面上的某些内容发生更改时关闭。

我为其他目的设置了 PageIndexChange 事件,我只想添加一些功能,如果 Gridview 索引发生更改,可能是脚本管理器以关闭子弹出页面,java 或其他最有效的方式。

我想我可能还需要检查子页面是否打开。

任何帮助和示例将不胜感激。

已编辑:这是打开弹出子页面的代码...

' Sets up popup to open when row selected for edit is cycled in DataRowBound event
    If IsPostBack Then
        If (e.Row.RowState And DataControlRowState.Edit) > 0 Then
            If Session("updateComplete") <> "Y" And Session("CancelUpdate") <> "Y" Then
                Dim BrowserSettings As String = "status=no,toolbar=no, scrollbars =yes,menubar=no,location=no,resizable=no," & "titlebar=no, addressbar=no, width=650, height=800"
                Dim URL As String = "pttStringPopUp.aspx"
                Dim scriptText1 As String = ("<script>javascript: var w = window.open('" & URL & "','_blank','" & BrowserSettings & "'); </script>")

                ScriptManager.RegisterStartupScript(Me, GetType(Page), "ClientScript1", scriptText1, False)
                Session("updateComplete") = "N"
            End If
        End If
    End If

谢谢,

【问题讨论】:

    标签: javascript asp.net vb.net


    【解决方案1】:

    您可以在RowDataBound 事件中附加onclick 处理程序,并在事件中关闭弹出窗口:

    protected void GridView1_RowDataBound(object sender, EventArgs e)
    {
        e.Row.Attributes["onclick"] = String.Format("rowClick({0});", e.Row.RowIndex); 
    }
    

    ASPX:

    var dialog;
    var selectedRowIndex;
    
    rowClick = function(rowIndex){
        if (selectedRowIndex){
            if (rowIndex != selectedRowIndex){ 
                selectedRowIndex = rowIndex;
                if (dialog){
                    dialog.close();
                }
            }
        }
    }
    

    【讨论】:

    • 这不起作用,因为必须允许用户离开子页面。如果 gridview 页面索引发生变化,我只能关闭孩子。除非我可以检查页面索引是否已更改,否则 RowDataBound 不会给我关闭子页面的理由。不知道如何做到这一点或如何从父页面关闭子页面。
    • 我认为您没有理解我的回答。我只是在RowDataBound 事件中将点击事件附加到GridViewRow。单击一行并触发 JavaScript 函数时关闭子窗口。
    • 我想我也需要关闭子窗口,也就是说,如果选择的行发生了变化,从导致弹出的行开始。嗯,我迷路了。
    • 当一行被选中时,是否会触发回发?
    • 相信我——这就是你需要开始的地方。现在只是解决细节问题。
    猜你喜欢
    • 1970-01-01
    • 2022-11-21
    • 2019-07-06
    • 1970-01-01
    • 2021-10-19
    • 1970-01-01
    • 1970-01-01
    • 2023-01-12
    相关资源
    最近更新 更多