下面是我打开模态对话框的JS函数:<script language="javascript">
function OpenWin(){
var str=window.showModalDialog('selorder.aspx','','dialogLeft=80px;dialogTop=80px;dialogWidth=650px;dialogHeight=450px');
if(str!=null)
document.getElementById("ctl00_ContentPlaceHolder1_txtPayMoney").value = str;
}
</script>
下面是selorder.aspx页面的主要代码:<asp:GridView ID="gdvOrders" runat="server" AutoGenerateColumns="False"
CssClass="mconttable" PageSize="5">
...
</asp:GridView>
<br />
<webdiyer:AspNetPager PageSize="5" ID="anpOrderByLocId" runat="server" FirstPageText='首'
LastPageText='尾' CssClass="pageindexlink" CurrentPageButtonClass="aaa" CustomInfoClass=""
PagingButtonSpacing="" OnPageChanged="anpOrderByLocId_PageChanged">
</webdiyer:AspNetPager>
<br />
<input type='button' name='bb' id='bb' style="width:80px" value='选择' runat="server" />
下面是selorder.aspx.cs页面的主要代码: protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// 通过登陆的用户名获取公司ID
DataTable dt = OrderDAO.SearchLocByUserName(Profile.UserName);
int locid = int.Parse(dt.Rows[0]["Id"].ToString()); // 公司ID
ViewState["locid"] = locid; anpOrderByLocId.RecordCount = OrderDAO.QueryOrderCount("CoLocId=" + locid); BindDataOrderByLocId(locid); bb.Attributes.Add("onclick", "window.parent.returnValue=76.78;window.close();");
}
} // 绑定订单数据,用于默认查询
private void BindDataOrderByLocId(int locid)
{
int startIndex = anpOrderByLocId.StartRecordIndex;
int endIndex = anpOrderByLocId.EndRecordIndex; gdvOrders.DataSource = OrderDAO.QueryOrderByLocId(locid, startIndex, endIndex);
gdvOrders.DataBind();
}
// 默认查询换页
protected void anpOrderByLocId_PageChanged(object sender, EventArgs e)
{
BindDataOrderByLocId(int.Parse(ViewState["locid"].ToString()));
}
可是我在弹出的模态对话框内点击换页的按键的时候就换不了页,不知道怎么回事,但是单独运行selorder.aspx是可以分页的,请大家帮帮忙!
function OpenWin(){
var str=window.showModalDialog('selorder.aspx','','dialogLeft=80px;dialogTop=80px;dialogWidth=650px;dialogHeight=450px');
if(str!=null)
document.getElementById("ctl00_ContentPlaceHolder1_txtPayMoney").value = str;
}
</script>
下面是selorder.aspx页面的主要代码:<asp:GridView ID="gdvOrders" runat="server" AutoGenerateColumns="False"
CssClass="mconttable" PageSize="5">
...
</asp:GridView>
<br />
<webdiyer:AspNetPager PageSize="5" ID="anpOrderByLocId" runat="server" FirstPageText='首'
LastPageText='尾' CssClass="pageindexlink" CurrentPageButtonClass="aaa" CustomInfoClass=""
PagingButtonSpacing="" OnPageChanged="anpOrderByLocId_PageChanged">
</webdiyer:AspNetPager>
<br />
<input type='button' name='bb' id='bb' style="width:80px" value='选择' runat="server" />
下面是selorder.aspx.cs页面的主要代码: protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// 通过登陆的用户名获取公司ID
DataTable dt = OrderDAO.SearchLocByUserName(Profile.UserName);
int locid = int.Parse(dt.Rows[0]["Id"].ToString()); // 公司ID
ViewState["locid"] = locid; anpOrderByLocId.RecordCount = OrderDAO.QueryOrderCount("CoLocId=" + locid); BindDataOrderByLocId(locid); bb.Attributes.Add("onclick", "window.parent.returnValue=76.78;window.close();");
}
} // 绑定订单数据,用于默认查询
private void BindDataOrderByLocId(int locid)
{
int startIndex = anpOrderByLocId.StartRecordIndex;
int endIndex = anpOrderByLocId.EndRecordIndex; gdvOrders.DataSource = OrderDAO.QueryOrderByLocId(locid, startIndex, endIndex);
gdvOrders.DataBind();
}
// 默认查询换页
protected void anpOrderByLocId_PageChanged(object sender, EventArgs e)
{
BindDataOrderByLocId(int.Parse(ViewState["locid"].ToString()));
}
可是我在弹出的模态对话框内点击换页的按键的时候就换不了页,不知道怎么回事,但是单独运行selorder.aspx是可以分页的,请大家帮帮忙!
<title>选择订单</title>
<!-- 防止重新打开页面形式的对话框 -->
<base target="_self" />
</head>
对,就是这个~ 预祝国庆节快乐!~~
<!-- 防止重新打开页面形式的对话框 -->
<base target="_self" /> 把target放在base标签中与放到控件标签内是有区别的,在模式对话框内,放在base中才管用
因为在IE里showmodaldialog这个函数在打开对话框时以打开的URL为准,如果你的URL没有改变,那么它打开的永远是第一次打开的内容,不论这个页面做过什么,打开的内容都是一样,举个例子,从数据库中读出一条记录显示在这个对话框的页面上,你会发现当你打开过一次后,即使数据库中这条记录的内容已经改过了,对话框上仍然显示以前的旧数据,这是IE的问题,它是以打开时的URL为准的,只要你的URL不变,内容就不变,解决的办法就是在URL后加一个随机数(像加个时间也行)。这样才能读到最新的数据。
现在在上班,这个网站要下午出台了..唉...好急好急...十一照常上班...
showModalDialog 打开的模态对话框有不少经典的缺陷,在这里不再冗述,我只谈谈最近碰到的几个问题以及解决办法。 问题1. showModalDialog 打开一个 aspx 页面时,如果该页面在之前已经打开过一次,则自动会加载缓存中的页面,而不能显示最新数据。 解决的办法有两种: (1). 在打开模态框时,给 url 后面多加一个随机参数,来避免页面被缓存: var url = 'EditFlowNode.aspx?flowId=0&id=2&x=' + Math.random();
var result = window.showModalDialog(url, '', 'status:no; help:no;'); (2). 在该 asp.net 页面的 Page_Load 方法里设定不缓存: protected void Page_Load(object sender, EventArgs e){
Response.Expires = 0;
Response.Cache.SetNoStore();
Response.AppendHeader("Pragma", "no-cache");
}
问题2. 模态对话框中的内容和脚本加载次序不同,导致的问题。 缘起:考虑如下页面的代码 <!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>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head> <body>
<input id="txt1">
<script type="text/javascript">
<!--
alert(document.getElementById('txt1').offsetWidth);
//-->
</script>
</body>
</html>
这个页面,如果在普通的 IE 窗口中加载时,提示的信息是 "155",而在模态对话框中执行时,其数值是 "0"。为什么会这样? 我们注意到普通窗口打开该页面时,当跳出 alert 对话框后,整个页面元素都已经正常显示了;而模态框在打开时,跳出 alert 对话框后,其背景却是一片空白;等点击“确定”后,才会显示出网页内容。
由此可以推测,模态框和普通页面在解析执行 HTML 时的次序不同: 普通页面:依次解析 body 中的元素,并随即绘制(render)解析完的元素。如果碰到 script, 则立刻执行之。 模态对话框:依次解析 body 中的元素,但并未立即绘制(render)它们。如果碰到 script, 则立刻执行之。等 body 都加载完毕后,再依次绘制其中的元素。 由于以上我们示例代码中访问到了 offsetWidth 属性,而我们可以推知,该属性一定是当元素被绘制(render)完毕后,才会自动计算出有意义的数值。所以就导致了问题中看到的现象。 之所以考虑到这个问题,其实是因为我在模态对话框中使用一个第三方控件的时候,出现了 bug,经过调试发现根源的原因在于该控件采用了常用的代码模式来输出其 HTML。也就是在一段 HTML 输出后,紧接着输出其初始化脚本。(这个问题值得 ASP.NET 控件开发者引起注意) 幸运的是,我有这个控件的源代码。因此修改源代码解决了这个问题。我的解法类似于这样:
<!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>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head> <body>
<input id="txt1">
<script type="text/javascript">
<!--
var _document_body_onload = document.body.onload;
document.body.onload = function(){
// 这里做你需要做的初始化动作
alert(document.getElementById('txt1').offsetWidth); if(_document_body_onload && typeof(_document_body_onload) == 'function')
_document_body_onload();
}
//-->
</script>
</body>
</html>