2012-04-25 31 views
0

我想获得一些独特的处理问题的帮助。鉴于这些限制,我正在寻找具体的解决方案。通过取消或更新按钮单击弹出返回到父页

我有一个弹出的aspx页面,从父页面gridview接收数据编辑点击。当父数据被弹出翻译时,大量的数据从父页面中解析出来,然后发送回父页面,在更新之前在原始文本块中重新组合。

当弹出窗口传回数据或取消时,父页面gridview仍处于编辑模式。

我想通过点击取消或更新按钮从弹出窗口到父页面gridview,因此它可以完成更新或取消事件,而不要求用户点击相应的命令按钮链接从gridview编辑模式,以更新或取消。

我真的很想找一个教程,链接或示例代码,因为我想完全理解如何做到这一点。

更新:父页面上还有一个jQuery UIBlocker,以防止用户返回到页面,直到PopUp页面处理完成。下面是关键代码:

父页面

function parentFunc(a) { 
    // Unblocks on return from popup page. 
    $.unblockUI({}); 
    document.getElementById("<%=Textbox1.ClientID %>").value = a; 

    alert("Please complete the update by entering a Brief Description then clicking the UPDATE link!!"); 
} 

function parentCancel(s) { 
    // Unblocks because of cancel from popup page. 
    // var a = 0; 
    $.unblockUI({}); 

    alert("Please click the Cancel link to complete the Cancel process!!"); 
} 

父页面代码背后,行Updatinfg事件建立字符串数组后,通过弹出页面。

' Sets up popup to open when row selected for edit is cycled. 
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=850, height=800" 
      Dim URL As String = "NewpttStringPopUp.aspx" 
      Dim dialog As String = URL 
      Dim scriptText1 As String = ("<script>javascript: var w = window.open('" & URL & "','_blank','" & BrowserSettings & "'); $.blockUI({ message: '<h1>Please translate text and click Submit...</h1>' }); </script>") 

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

POPUP页

function closeform() { 
    alert("Please click the Cancel Button at the buttom of the page to Cancel the process!!"); 

    return "Please click the Cancel Button at the buttom of the page to Cancel the process!!"; 
    } 

function handleWindowClose() { 
    if ((window.event.clientX < 0) || (window.event.clientY < 0)) { 
     event.returnValue = "If you have made any changes to the fields without clicking the Save button, your changes will be lost."; 
    } 
} 

function callParentFunc() 
{ 
    var w = window.opener; 
    var a; 
    if (!w.closed) { 
     var val = w.parentFunc(a); 
     self.close(); 
    } 
    this.window.focus() 
} 

function callParentCancel() { 
    var w = window.opener; 
    var s; 
    if (!w.closed) { 
    var val = w.parentCancel(s); 
    self.close(); 
    } 
} 

POPUP.ASPX.VB代码隐藏取消按钮

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click 
    ' Cancel Button so that no update is processed. 
    ' Sets flag to prevent java popup from reopening after RowUpdating event. Occurs in RowDataBound event. 
    'Dim s As String = "c" 
    Dim strScript2 As String = "callParentCancel();" 
    ClientScript.RegisterStartupScript(GetType(Page), "callParentCancel", strScript2.ToString, True) 

    Session("UpdateEnd") = "Y" 
    Session("CancelUpdate") = "Y" 
    'Response.Write("<script>window.close();</script>") 
End Sub 

POPUP.ASPX.VB后面的代码提交按钮

不显示构建arrary的个

工艺breivity ..

Session("returnTranslation") = arReturn 

    ' Page.PreviousPage.Focus() 

    Dim strScript As String = "callParentFunc();" 
    ClientScript.RegisterStartupScript(GetType(Page), "callParentFunc", strScript.ToString, True) 

    ' Sets flag to prevent java popup from reopening after RowUpdating event. Occurs in RowDataBound event. 
    Session("updateComplete") = "Y" 

有一个问题,防止弹出从重装。所以在加载事件中有一个if条件。动态数量的控件构建在弹出文本上。因此,页面初始化事件和页面加载事件在非回发时触发来重建控件。

谢谢,所有的建议将被审查。

回答

0

最好的办法是建立在家长的JavaScript函数,并使用window.opener从弹出访问:

在父

processGridCommand = function(command){ 
    __doPostBack("<%= GridView1.ClientID %>", command); 
    return false; 
} 

从孩子

<script type="text/javascript"> 
    updateParentGrid = function(command){ 
     if (window.opener){ 
      window.opener.processGridCommand(command); 
     } 
     return false; 
    } 
</script> 
<asp:Button ID="Button1" runat="server" Text="Click" OnClientClick="return updateParentGrid('Update');" /> 

处理p ostback父

这将触发父回发,并重写RaisePostBackEvent方法的代码隐藏,你可以处理它需要:

protected override void RaisePostBackEvent(IPostBackEventHandler source, string eventArgument) 
{ 
    base.RaisePostBackEvent(source, eventArgument); 
    if (source == GridView1) 
    { 
     switch (eventArgument) 
     { 
      "Update": 
       //perform update logic 
       break; 
      "Cancel": 
       //cancel edit mode 
       break; 
     } 
    } 
} 
+0

感谢詹姆斯,我更新了OP我的代码。你可以看一下吗? – htm11h 2012-04-27 13:21:00