asp.net 中为什么在showModalDialog弹出的窗体 用html 控件 刷新不了页面。而用服务器端控件 写C#代码可以刷新页面。但是用服务器端刷新页面不好。
2013-04-10 23:55
881 查看
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 方法,或其他方法怎么实现页面的刷新(时间要改变)。
代码:<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>");
}
求助给位大侠帮我看看,谢谢。
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 方法,或其他方法怎么实现页面的刷新(时间要改变)。
代码:<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>");
}
相关文章推荐
- [ASP.NET]如何点击按钮弹出新窗口,输入数据后返回并刷新页面?(C#代码)
- [ASP.NET]如何点击按钮弹出新窗口,输入数据后返回并刷新页面?(C#代码)
- asp.net中利用showModalDialog弹出模态窗体后刷新父窗体
- 在C# ASP.NET中,要添加属性到控件中 在HTML页面获取控件中自己定义属性和值
- C# ASP.NET中无刷新页面 弹出对话框,并且页面跳转
- C# ASP.NET中无刷新页面 弹出对话框,并且页面跳转
- asp.net 后台代码跳转页面前弹出提示框【C#后台提示后调转页面大全
- 将Asp.Net页面输出为HTML(c#)
- asp.net 中将表单提交到另一页 Code-Behind(代码和html在不同的页面)
- Silverlight4里面嵌入html页面或者asp.net(jsp)控件实现
- asp.net 2.0 中用C#代码在C:/Inetpub/wwwroot下创建目录,创建文件,写文件等有权限问题,可以用FSO方式
- asp.net服务端代码如何获取客户端控件的值(HTML控件)
- Asp.net 2.0 自定义控件开发专题[详细探讨页面状态(视图状态和控件状态)机制及其使用场景](示例代码下载)
- HTML控件ID和NAME属性的区别,以及如何在asp.net页面的.CS文件中获得.ASPX页面中HTML控件的值
- 如何在ASP.NET的代码中增加页面自动刷新
- ASP.NET后台代码方式识别页面“按钮点击”和浏览器F5“刷新”事件
- 【C#】对异步请求处理程序IHttpAsyncHandler的理解和分享一个易用性封装 【手记】走近科学之为什么明明实现了IEnumerable<T>的类型却不能调用LINQ扩展方法 【手记】手机网页弹出层后屏蔽底层的滑动响应 【手记】ASP.NET提示“未能创建类型”处理 【Web】一个非常简单的移动web消息框 【手记】解决EXCEL跑SQL遇“查询无法运行或数据库表无法打开...”
- dhl:asp.net mvc下用jQuery ajax方法实现无刷新分页(用户控件)& 整体页面无刷新(2010-11-13 add)
- Asp.net中小技巧—服务器端Web控件与客户端Html控件交互
- 让服务器控件执行js与C#两种代码(asp.net)