我想就独特的处理问题获得一些帮助。鉴于这些限制,我正在寻找具体的解决方案。
我有一个弹出式aspx页面,它从父页面gridview接收数据编辑点击。当弹出数据时,父页面会弹出很多数据,然后弹出,然后发送回父页面,在更新之前在原始文本块中重新组装。
当弹出窗口传回数据或被取消时,父页面gridview仍处于编辑模式。
我想将“取消”或“更新”按钮单击从弹出窗口传递到父页面gridview,以便它可以完成更新或取消事件,而无需要求用户单击从gridview编辑模式的相应命令按钮链接到更新或取消。
我正在寻找教程,链接或示例代码,因为我想完全了解如何执行此操作。
更新:在Parent页面上还有一个jquery UIBlocker,以防止用户返回页面,直到PopUp页面处理完成。以下是关键代码:
PARENT Page :
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!!");
}
PARENT PAGE Code Behind ,在构建字符串数组以传递到POPUP页面之后的行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();
}
}
CANCEL BUTTON背后的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代码
建筑工作的过程不会因为突发事件而显示..
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"
阻止弹出窗口重新加载有问题。所以在load事件中有一个if条件。动态数量的控件在弹出窗口上构建为文字。因此,Page Init事件和Page Load事件在非Postback上触发以重建控件。
谢谢,所有建议都将得到审核。
答案 0 :(得分: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');" />
处理家长的回发
这将触发父级的回发,并覆盖代码隐藏中的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;
}
}
}