var waiting_win;  function OpenWaiting() {
            waiting_win = window.open('../waiting.aspx', 'WaitingWin', 'left='
        + (screen.availWidth - 300) / 2 + ',top='
        + (screen.availHeight - 200) / 2 + ',width=300,height=200');
        }        function window_OnUnLoad() {
            alert(waiting_win);
            if (typeof (waiting_win) != "undefined" && waiting_win != null) {
                try {
                    waiting_win.opener = null;                    waiting_win.close();
                }
                catch (ex) { }
            }
        }OpenWaiting方法是赋给了一个button.attribute.add("onclick","")这种方式。而window_OnUnLoad()方法则是在button的事件执行成功之后调用的
 ClientScript.RegisterStartupScript(ClientScript.GetType(), "12", "<script>window_OnUnLoad();</script>");,可是这里无法关闭这个提示框。
alert(waiting_win);这段代码竟然提示"undefined"
waiting.aspx这个页面就是显示一个耗时提示,如下图:

解决方案 »

  1.   

    有可能是你js方法写的地方不对,可能你调用这方法的时候还没初始化。 把它写在最前面试试?
    ClientScript.RegisterStartupScript(ClientScript.GetType(), "12", "<script>window_OnUnLoad();</script>");,
    看看你页面源码 看看是否注册成功??????
    还有你好像逻辑有点问题: OpenWaiting方法是赋给了一个button.attribute.add("onclick","")这种方式。而window_OnUnLoad()方法则是在button的事件执行成功之后调用的;OpenWaiting也应该在后台注册才有效果 不然运行服务器端代码 那你js变量值肯定不会存在了啊
      

  2.   

    deferClientScript.RegisterStartupScript(ClientScript.GetType(), "12", "<script defer>window_OnUnLoad();</script>");,
      

  3.   


    ClientScript.RegisterStartupScript(ClientScript.GetType(), "12", "<script>window_OnUnLoad();</script>");,
      

  4.   

    在页面加载前加载OpenWaiting。$.ready();事件中加载window_OnUnLoad();
      

  5.   

    估计是点击按钮postback了,页面刷新,waiting_win就是undefined了。
      

  6.   

    aspx页面head中定义一个waiting_win先
    var waiting_win;
      

  7.   

    这样测试效果还是一样的
    同样提示undefined
      

  8.   

        <form name="form1" method="post" action="Default.aspx" id="form1">
    <div>
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMjA0OTM4MTAwNA9kFgICAw9kFgICAQ8PZBYCHgdvbmNsaWNrBQ1PcGVuV2FpdGluZygpZGQzVD93klhGC7dtK58mhv0l2gLb3Q==" />
    </div><div> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgKKhpGADQLcu4S2BAkMuQLquYRQ80GZ20fY4Fxk8Pxm" />
    </div>
        <div>
            <input type="submit" name="submit" value="执行" onclick="OpenWaiting();" id="submit" />
        </div>
        
    <script >window_OnUnLoad();</script></form>
      

  9.   

    比较明显  当alert发生的时候 还么有waiting_win 这个方法  请注意 JS的执行顺序  一定要保证waiting_win 初始化之后 再去调用它  才行至于 ClientScript.RegisterStartupScript  会把<script>window_OnUnLoad();</script>放到页面的什么位置 这就要靠你自己去调试  去推敲了  呵呵 
      

  10.   

    aspx页面head中定义一个var waiting_win;  function OpenWaiting() {
                waiting_win = window.open('../waiting.aspx', 'WaitingWin', 'left='
                + (screen.availWidth - 300) / 2 + ',top='
                + (screen.availHeight - 200) / 2 + ',width=300,height=200');
                return false;
            }设置submit按钮不提交(回发) UseSubmitBehavior="false"
      

  11.   

    head中定义waiting_win??
    <head>
    var waiting_win;
    </head>
    这样可以??
    设置submit按钮不提交(回发) UseSubmitBehavior="false"
    可是我真正的应用程序是点击按钮是需要做操作很多事情的
      

  12.   

    是可以搞定的
    两个方法同时都用client.register方法注册就行
    可是我这样控制不了这个弹出窗口的打开与关闭的时间啊像我现在是需要点击按钮把弹出框打开,然后按钮的事情里操作完成之后再关闭。
      

  13.   

    ClientScript哪个方法是把脚本注册到<head></head>中去的?
      

  14.   

      protected void Page_Load(object sender, EventArgs e)
            {
                ClientScript.RegisterStartupScript(ClientScript.GetType(), "12555", "<script >OpenWating();</script>");
            }        protected void submit_Click(object sender, EventArgs e)
            {
                System.Threading.Thread.Sleep(10000);
                ClientScript.RegisterClientScriptBlock(ClientScript.GetType(), "12", "<script >window_OnUnLoad();</script>");        }
      

  15.   

    如果是undefined是因为你的弹出窗口还没关闭,所以返回值是undefined。
      

  16.   

    不用ClientScript用变量 <%= %>
      

  17.   

    protected string js;<head>
    <%= js%>
    </head>js="<script >window_OnUnLoad();</script>";
      

  18.   

    大家明白意思吗?
    我要是同时把打开新窗口和关闭新窗口的代码全放到点击按钮事件里去执行的话,那这两段代码都是同时执行了。
    ClientScript.RegisterStartupScript(ClientScript.GetType(), "12555", "<script >OpenWating();
    ClientScript.RegisterClientScriptBlock(ClientScript.GetType(), "12", "<script >window_OnUnLoad();
    也就是说根本无法打开新窗口。
    所以我就是想在 button.attribute.add(onclick)放openWaiting方法而在按钮事件里放window_OnUnload()方法关闭窗口我想实现的功能就是当点击按钮的时候弹出提示正在执行。当执行完毕之后有返回值或者报错就把弹出窗口给关闭
      

  19.   

    非哥,你这个是定义JS还是调用JS?
      

  20.   

    非哥,你那方法不管用,同样报undefined错误    protected string closeJs;
            protected void Page_Load(object sender, EventArgs e)
            {
                submit.Attributes.Add("onclick", "OpenWaiting()");
            }        protected void submit_Click(object sender, EventArgs e)
            {
                System.Threading.Thread.Sleep(10000);            closeJs = "<script>window_OnUnLoad();</script>";
            }
    <head runat="server">
        <title></title>    <script language="javascript" type="text/javascript">
            var waiting_win;
            function OpenWaiting() {
                waiting_win = window.open('../waiting.aspx', 'WaitingWin', 'left='
                     + (screen.availWidth - 300) / 2 + ',top='
                     + (screen.availHeight - 200) / 2 + ',width=300,height=200');
            }        function window_OnUnLoad() {
                alert(waiting_win);
                if (typeof (waiting_win) != "undefined" && waiting_win != null) {
                    try {
                        waiting_win.opener = null;                    waiting_win.close();
                    }
                    catch (ex) { }
                }
            }
        </script>    <%=closeJs %>
    </head>
      

  21.   


       protected string closeJs;
            protected string openJs;
            protected void Page_Load(object sender, EventArgs e)
            {
            }        protected void submit_Click(object sender, EventArgs e)
            {
                openJs = "<script>OpenWaiting();</script>";
                System.Threading.Thread.Sleep(10000);            closeJs = "<script>window_OnUnLoad();</script>";
            }后台代码要是改成这样是可以的。
    可是根本不会弹出框来,而是过了十秒之后再弹出然后立刻关闭。
    与我想要的效果不一样呀
      

  22.   

    报undefined错误应该是因为编译时给判断成后台方法了,前几天在做个网页时用到JS函数就老是报这错。如果你要给按钮添加方法的话不如页面写好方法,然后给按钮添加onclientclick方法,就别通过后台了(onclick是后台的)
      

  23.   

    弹出层+iframe 应该可以实现
      

  24.   

    OpenWaiting方法是赋给了一个 button.attribute.add("onclick","")这种方式。而window_OnUnLoad()方法则是在button的事件执行成功之后调用的错估计就在这里了,你的OpenWaiting 是在客户端点击事件里加载的,而你的button提交到服务器后,返回的是一个新页面,重新加载的,,它哪来的 waiting_winwaiting_win 当然未定义了。。所以这里不能改变当前页面状态,,要AJAX
      

  25.   

    那把我目前的项目用ajax咋用啊
    我对ajax不懂,所以没用。
      

  26.   

     protected string closeJs;
            protected string openJs;
            protected void Page_Load(object sender, EventArgs e)
            {
            }        protected void submit_Click(object sender, EventArgs e)
            {
                openJs = "<script>OpenWaiting();</script>";
                System.Threading.Thread.Sleep(10000);            closeJs = "<script>window_OnUnLoad();</script>";
            }这种方法就对了
    可是它弹出框不是执行到            openJs = "<script>OpenWaiting();</script>";这里弹出来。
    而是需要整个button事件完毕 了和再弹出来,也就是说弹出和关闭同时进行了
    杯具。。
      

  27.   

    其实把window_UnLoad()方法放到body的unload事件中是可以的
    只不过因为我还有另外一个unbeforeunload事件已经放在body里了
    所以我需要在后台执行window_UnLoad方法。
    难道就没有好的方法了吗
      

  28.   


    protected void submit_Click(object sender, EventArgs e)
      {
      openJs = "<script>OpenWaiting();</script>";
      System.Threading.Thread.Sleep(10000);  closeJs = "<script>window_OnUnLoad();</script>";
      }
    这种方法根本就没有作用,,逻辑有问题,,服务器执行完了,,才把JS 发回客户端的,所以 相当于 用户要毫无意义的等进度条滚动,,事实上操作执行完了可以说这种方法是错的
      

  29.   

    那pengyi_205有什么好办法
    在我现有的这些代码上。
      

  30.   

    waiting_win undefined了应该是你找不到waiting_win你查看源文件玩玩。。
      

  31.   


    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>    <script type="text/javascript">
            var waiting_win;
            function OpenWaiting() {
                waiting_win = window.open('Canledar.aspx', 'WaitingWin', 'left=' + (screen.availWidth - 300) / 2 + ',top=' + (screen.availHeight - 200) / 2 + ',width=300,height=200');
            }        function window_OnUnLoad() {
                if (typeof (waiting_win) != "undefined" && waiting_win != null) {
                    try { waiting_win.opener = null; waiting_win.close(); } catch (ex) { }
                }
            }
            function Excute() {
                OpenWaiting();
                PageMethods.ExecuteFun(CloseMsg);
            }        function CloseMsg(res) {
                if (res == "true") {
                    window_OnUnLoad();
                }
            }
        </script></head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
        </asp:ScriptManager>
        <input type="button" value="执行" onclick="Excute();" />
        </form>
    </body>
    </html>   [WebMethod]
        public static string ExecuteFun()
        {
            System.Threading.Thread.Sleep(10000);
            return "true";
        }
    简单的一个小例子,,看是不是你想要的
      

  32.   

    http://topic.csdn.net/u/20100629/09/6085df9e-8d85-48be-a63e-a3fabb9fc18b.html
    我想要做的基本上都在这里面。
      

  33.   

    额,,不想用控件,,用客户端回调,,自写AJAX 都可以..
      

  34.   

    帖子链接
    http://topic.csdn.net/u/20100629/15/6f50440d-a291-4f5f-a57e-bb2f637c2905.html
    现在应该会看得懂
      

  35.   


    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>    <script>
            var waiting_win;        function OpenWin() {
                waiting_win = window.open('waiting.aspx', 'WaitingWin', 'left='
                + (screen.availWidth - 300) / 2 + ',top='
                + (screen.availHeight - 200) / 2 + ',width=300,height=200');
            }
            function CloseWin() {
                if (typeof (waiting_win) != "undefined" && waiting_win != null) {
                    try {                    waiting_win = window.open('waiting.aspx', 'WaitingWin', 'left='
                + (screen.availWidth - 300) / 2 + ',top='
                + (screen.availHeight - 200) / 2 + ',width=0,height=0');                    waiting_win.opener = null;                    waiting_win.close();
                    }
                    catch (ex) { }
                }        }
        </script></head>
    <body>
        <form id="form1" runat="server">
        <asp:Button ID="btn" runat="server" OnClientClick="OpenWin();" OnClick="btn_Click"
            Text="Submit" />
        </form>
    </body>
    </html> protected void btn_Click(object sender, EventArgs e)
        {
            System.Threading.Thread.Sleep(5000);
            ClientScript.RegisterStartupScript(GetType(), "CloseWin", "waiting_win='WaitingWin'; CloseWin();", true);
        }
      

  36.   

    非哥,我那个创建报表按钮是一个工具条上的按钮
    只能通过attribute.add方式添加
    比如this.btn.attribute.add("onclientclick")这种方式也可以的吧?
      

  37.   

    http://topic.csdn.net/u/20100628/16/2f577ab2-b341-4453-b40a-1d74f9d4970c.html非哥,最麻烦的问题在这里。有做过这方面吗?
      

  38.   

    this.submit.Attributes.Add("onclientclick", "OpenWaiting()");
    弹不出框来,用这样写的话,你那种方法可以 
      

  39.   


    ---------------------------
    this.submit.Attributes.Add("onclientclick", "OpenWaiting()");=》this.submit.Attributes.Add("onclick", "OpenWaiting()");