我现在用gridview展示了一些条目,想在在每条条目后添加一个举报按钮(后台控件),给举报按钮定义了前台事件(为了实现无刷新),单击按钮后打开一个一个子页面,在子页面填写举报相关内容后,填好后返回一个值给父窗口,父窗口根据这个值,判断是否执行回调函数,从而改变该条目的状态。
过程就是这样,问题1:这个按钮其实做了两件事,一是打开子窗口,二是子窗口操作完成后返回一个值,用以判断是否执行父窗口的回调函数,不知道这两个过程会不会冲突,父窗口怎么得到子窗口的值。
希望能各位能给点建议,给个demo代码更好。

解决方案 »

  1.   

    window.returnvalue
    子窗体这样设置返回值 父窗口取
      

  2.   

    var a = window.showModalDialog("aa.aspx");alert(a);在aa.aspx中,做完操作后.window.returnValue = 123;
    window.close();
    那么父窗口中的a就是123
      

  3.   

    给你个例子
    <asp:ImageButton ID="ImgBtn_Project" runat="server" ImageUrl="~/Image/Button/LVBtnXZQY.gif" onclick="ImgBtn_Project_Click" 
    onclientclick="return btn_project_onclick()" />      
    这个ImageButton有两个事件 onclientclick="return btn_project_onclick()"   //前台的
    onclick="ImgBtn_Project_Click"                 //后台的前台方法代码:
    function btn_project_onclick() {
    var returnValue=window.showModalDialog("../Order/SelectProject.aspx",'window','dialogWidth=600px;dialogHeight=500px');//这句话是弹出一个宽600px;高500px的窗口。记得一定定义returnValue接受这个弹出窗口。
    他将会给你到有个值回来。这好有个好处。就是那个后台方法,如果你想返回来值后还想调用后台处理东东的话,你可以把后台方法也加上,他将在返回值后才会运行,意思是你返回值后,前台处理完毕之后,就会执行后台代码。下面是判断返回来的值。
           if(returnValue==undefined||returnValue==null||returnValue==",")
           {
            alert("没有选择企业!");
           }
           else
           {
           
           var s=returnValue.split(",");
            window.document.getElementById("HiddenField1").value=s[0];
            window.document.getElementById("txt_projectName").value=s[1];
            alert(window.document.getElementById("HiddenField1").value);
            
           }
    }这个下面呢就是写在弹出那个窗口的前台方法。
    function Btn_ok_onclick() {
     window.returnValue = document.all("HiddenField1").value + "," + document.all("txt_Name").value; //给要返回的window.returnValue赋值。
            window.close(); //关闭窗口
    }
       够详细了吧。。
      

  4.   

    要用服务器的btn哦。。只要是服务器的都行。
      

  5.   

    我那个也是跟你差不多。父窗口同过一个IMGBtn跳转到另一个子窗口,子窗口在关闭的时候将带回来一个值ID。ID存在returnValue中,然后再去判断他是否有值。后面的那就应该清楚了。你可以去试试。当他执行到父窗口JS里的var returnValue=window.showModalDialog("../Order/SelectProject.aspx",'window','dialogWidth=600px;dialogHeight=500px');他会停下来等待子窗口的回复。然后再执行完下面的JS。。
      

  6.   

    不用服务器的btn
    用<input type="button"就可.
      

  7.   

    http://blog.csdn.net/cpp2017/archive/2007/02/27/1515474.aspx
      

  8.   

    看看我这段代码符不符合要求:
    Default4.aspx:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
        </form>
    </body>
    </html>
    default4.aspx.cs
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;public partial class Default4 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {    }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "open", "open('Default5.aspx');", true);
        }
    }default5.aspx:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:RadioButtonList ID="RadioButtonList1" runat="server">
                <asp:ListItem>1</asp:ListItem>
                <asp:ListItem>2</asp:ListItem>
            </asp:RadioButtonList></div>
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
        </form>
    </body>
    </html>default5.aspx.cs:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;public partial class Default5 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {    }
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (RadioButtonList1.SelectedValue=="1")
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "submit", "window.opener.document.getElementById('form1').submit()", true);
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "cancel", "window.opener.document.getElementById('Button1').value='你点了取消'", true);
            }
                    
        }
    }
      

  9.   

    我也顺便提个问题
    关于showModalDialog()方法只是在IE下可用,所以考虑到兼容的问题,是否有什么好的方法,能够替代这个方法
      

  10.   

    是不是在模态窗口引用window.opener是不是空,即所谓的屏蔽主窗口!
      

  11.   


    var a = window.showModalDialog("aa.aspx"); alert(a); 
    在aa.aspx中,做完操作后. window.returnValue = 123; 
    window.close(); 
    那么父窗口中的a就是123 
      

  12.   

    现在不用这种方法了
    变通使用更灵活了
    1. 
    aspx: <table style="width: 100%" runat ="server" id = "KongJian"> 
    .cs: KongJian.Visible = true; 
    ------------------------------------------------------------ 
    2. <asp:View ID="View4" runat="server"> 以上两种方法任意发挥。