showModalDialog关闭刷新父页面的问题

罗夏2021 2012-03-26 06:33:39
我的父页面Default.aspx里由函数
function OpenWin(ID) {

var strUrl = "ProductUpdate.aspx?ID=" + ID;
var returnValues1 = window.showModalDialog(strUrl, window, "resizable=no;dialogWidth:750px;dialogHeight:650px;status:no;help:no;");
if (returnValues1 == "ok") {
window.location.href = window.location.href;
}
return false;
}


后台用 Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>OpenWin(" + id + ")</script>"); 打开子窗口ProductUpdate.aspx
在子窗口ProductUpdate.aspx后台更新之后
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('更新成功');window.returnValues1=\"ok\";window.close();</script>");
但是父窗口ProductUpdate.aspx没有刷新。请问我该怎么做?

...全文
308 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
还想懒够 2012-03-27
  • 打赏
  • 举报
回复
在showModalDialog后面加入一句

debugger;


然后开启IE的javascript调试,弹出窗口点击确定后,会弹出提示让你选择调试器的,看看生成的returnValue是多少,或者简单一点,alert(returnValues1);

绑定的事件在GridView_RowDataBound事件中,仔细看看我回复的部分
罗夏2021 2012-03-27
  • 打赏
  • 举报
回复
可以打开了,但是就是没有刷新呀,我早if (returnValues1 != null) {
return true;
}
return false;
里加了
if (returnValues1 != null) {
window.location.href = window.location.href;

return true;
}
return false;
也没有刷新
罗夏2021 2012-03-27
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 jjkk168 的回复:]
1.父窗体部分(页面)

把btEdit_Click的后台代码去掉!

function CheckAndOpenWin()
{
var iSelectedCount = 0;
var itemID='';
$('#<%=GridView1.ClientID %>').find('input').each(function(){

if($(thi……
[/Quote]
当前台运行到itemID = $(this).parent.attr('ItemID'); 时出现了Microsoft JScript 运行时错误: 对象不支持此属性或方法
我想后台没有能把gridview1的键值id赋给ItemID.
即 Checkbox.Attributes.Add("ItemID",drv["ID"].ToString());
请问怎么将 gridview1 的DataKeys[id].tostring绑定给checkbox,
急,在线等
懒得起名字 2012-03-27
  • 打赏
  • 举报
回复
window.location.href = window.location.href;
再重新定位一下
罗夏2021 2012-03-27
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wbaoning 的回复:]
可以打开了,但是就是没有刷新呀,我早if (returnValues1 != null) {
return true;
}
return false;
里加了
if (returnValues1 != null) {
window.location.href = window.location.href;

return true;
}
return f……
[/Quote]可以了谢谢
还想懒够 2012-03-26
  • 打赏
  • 举报
回复

1.父窗体部分(页面)

把btEdit_Click的后台代码去掉!

function CheckAndOpenWin()
{
var iSelectedCount = 0;
var itemID='';
$('#<%=GridView1.ClientID %>').find('input').each(function(){

if($(this).attr('type')=='checkbox' && $(this).is(':checked'))
{
iSelectedCount++;
itemID=$(this).parent().attr('ItemID');
}

});

if(iSelectedCount==0)
{
alert('请选择一个项编辑');
return false;
}

if(iSelectedCount>1)
{
alert('一次只能编辑一个项');
return false;
}

var strUrl = "ProductUpdate.aspx?ID=" + itemID;
var returnValues1 = window.showModalDialog(strUrl, window, "resizable=no;dialogWidth:750px;dialogHeight:650px;status:no;help:no;");
if (returnValues1 != null) {
return true;
}
return false;

}

<asp:Button ID="btEdit" runat="server" OnClientClick="return CheckAndOpenWin();" />


2.父窗体部分(后台代码)

父页面中btEdit按钮不需要有任何的后台代码
绑定GridView的代码放到Page_OnPreRender中去

GridView的RowDataBound事件中写入如下代码
if(e.Row.RowType==DataControlRowType.DataRow)
{
DataRowView drv = e.Row.DataItem As DataRowView;//假定你绑定的是DataTable
CheckBox Checkbox = e.Row.FindControl("Checkbox") As CheckBox;
Checkbox.Attributes.Add("ItemID",drv["ID"].ToString());
}

3. 子窗体页面
弹出的子窗体的页面部分加一句javascript
window.returnValue=null;

4. 子窗体后台代码
子窗体后台代码当保存完毕并关闭时写入的后台代码应当为:
Page.ClientScript.RegisterStartupScript(this.GetType(),"returnValue","window.returnValue='ok';window.close();",true);
罗夏2021 2012-03-26
  • 打赏
  • 举报
回复
附上父页面编辑事件的代码,因为点击编辑时打开那个子窗口,
#region 编辑
protected void btEdit_Click(object sender, EventArgs e)
{


int count = 0; // 计算选择checkbox的个数;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
bool isCheck = ((CheckBox)GridView1.Rows[i].FindControl("Checkbox")).Checked;
if (isCheck)
{
count++;
}
}
if (0 == count)
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"","<script>alert('请选择一个项编辑')</script>");
}
else if (count > 1)
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('一次只能编辑一个项')</script>");
}
else
{
for (int j = 0; j < GridView1.Rows.Count; j++)
{
CheckBox Cb = (CheckBox)GridView1.Rows[j].FindControl("Checkbox");
if (Cb.Checked)
{
int id = Convert.ToInt32(GridView1.DataKeys[j]["id"].ToString());

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>OpenWin(" + id + ")</script>");

}
}
}
}

#endregion

62,267

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧