首页 新闻 赞助 找找看

asp.net 中为什么在showModalDialog弹出的窗体 用html 控件 刷新不了页面。而用服务器端控件 写C#代码可以

0
悬赏园豆:5 [已解决问题] 解决于 2015-09-08 13:40

asp.net 中为什么在showModalDialog弹出的窗体 用html 控件 刷新不了页面。而用服务器端控件 写C#代码可以刷新页面。但是用服务器端刷新页面不好。 如果我定义要用html控件,js方法怎么实现test2.aspx页面的刷新。

求助给位大侠帮我看看,谢谢。

test1.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test1.aspx.cs" Inherits="WebApplication4.hua" %>

<!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>
    <script type="text/javascript">
        function onpen() {
            var newurl = 'test2.aspx';
            var hei = 'dialogHeight:500px;dialogWidth:660px';
            window.showModalDialog(newurl, null, hei);
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
       <input type="button" onclick="onpen();" value="弹出"/>
    </div>
    </form>
</body>
</html>

test2.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test2.aspx.cs" Inherits="WebApplication4.tanhua" %>

<!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">
    <base target="_self"/>//不能去掉
    <title></title>
    <script type="text/javascript">
        function SetVal() {
            //            var num = document.getElementById("txtNum").value;
            //            if (num == "") {
            //                document.getElementById("txtNum").value = 0;
            //            } else {
            //                document.getElementById("txtNum").value = num+1;
            //            }
            var dt = Date();
            document.getElementById("txtNum").value = dt;
        }
        function Refresh() {
            //debugger;
            window.location.reload();
            //window.location.href = window.location.href;
            //document.execCommand("Refresh");
            //window.location.reload(location.href)
        }
    </script>
</head>
<body onload="SetVal()">
    <form id="form1" runat="server">
        <div>
            <input type="text" id="txtNum"  style=" width:500px;" /> 
            <input type="button" id="btnRefresh" value="刷新" onclick="Refresh();"  runat="server"/>
            <asp:Button  Text="test" runat="server" ID="test" onclick="test_Click"/>
        </div>
    </form>
</body>
</html>

 

test2.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication4
{
    public partial class test2: System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //btnRefresh.Attributes.Add("onclick", "Refresh();");
        }

        protected void test_Click(object sender, EventArgs e)
        {
            Page.ClientScript.RegisterClientScriptBlock(Page.ClientScript.GetType(), null, "<script>window.location.reload();</script>");
        }
    }
}

打开test1.aspx 出现:

点击弹出按钮 出现 新的窗体test2.aspx:

 

 

点击刷按钮,时间没变,说明没有刷新页面。但是点击test按钮就可以刷新页面。 

如果用html 控件 javascript 方法,或其他方法怎么实现页面的刷新(时间要改变)。

 

Hamilton Tan的主页 Hamilton Tan | 初学一级 | 园豆:167
提问于:2012-11-27 16:42
< >
分享
最佳答案
0

多谢各位大侠的帮助,问题很早就解决了,谢谢。

代码:<style type="text/css">
       .btnr{ display:none;}
    </style>

<input type="button" id="Button1" value="刷新2" runat="server" onclick="javascript:document.getElementById('btnR').click();"/>
<asp:Button  Text="1" runat="server" ID="btnR" onclick="btnR_Click" CssClass="btnr"/>

C# :

        protected void btnR_Click(object sender, EventArgs e)
        {
            Page.ClientScript.RegisterClientScriptBlock(Page.ClientScript.GetType(), null, "<script>window.location.reload();</script>");
        }

Hamilton Tan | 初学一级 |园豆:167 | 2013-10-26 11:36
其他回答(4)
0

用window.location.href = window.location.href;是可以的?你可以试着用artdiag,挺好用的。

收获园豆:5
happydaily | 园豆:301 (菜鸟二级) | 2012-11-27 17:58
0

因为服务器的控件默认就是会刷新页面。一般要 window.location.href = window.location.href;是可以的,可能是由于浏览器缓存的影响,这个可以通过 HTTPWATCH 的软件的检查。

geass.. | 园豆:1821 (小虾三级) | 2012-11-27 20:14
0

这样问题你先断点调试下,然后再找方法解决,除了以上园友提供办法,你在windows前加this试试,也不确定

伏草惟存 | 园豆:1420 (小虾三级) | 2012-11-27 23:28
0

我倒是记得showModalDialog是被禁用刷新的。

拾梦小侠ด้้้ | 园豆:713 (小虾三级) | 2012-11-28 13:33
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册