使用模态窗口编辑数据

该博客转载了一篇文章,原文链接为https://www.cnblogs.com/BillChen/archive/2005/09/08/232275.html ,涉及测试和JavaScript领域。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

为提高客户的体验,经常使用模态窗口。以下为使用的一个例子。

1、建立一个含有iframe的html文件,用于防止自刷新的问题。
Fram.htm
None.gif<html>
None.gif    
<head>
None.gif        
<title>在模态窗口中打开的框架页</title>
None.gif    
</head>
None.gif    
<body topmargin="0" leftmargin="0" scroll="no">
None.gif        
<iframe width="100%" height="100%" border="0" id="frame1"></iframe>
ExpandedBlockStart.gifContractedBlock.gif        
<script Language="Javascript">dot.gif
InBlock.gif        
var el=document.frames.frame1;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if(el!=null)dot.gif{
InBlock.gif        
var arg=window.dialogArguments;
InBlock.gif        
if(arg!=null)
InBlock.gif        frame1.location.href
=arg;
ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif        
</script>
None.gif    
</body>
None.gif
</html>

2、 在要打开模态窗口的起始处,编写如下函数:
None.gif        private string GetOpenModalDialogScript(int width, int height)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif            StringBuilder sb 
= new StringBuilder();
InBlock.gif            sb.Append(
"<script language='javascript'>");
InBlock.gif            sb.Append(
"function EditStructure(arg)");
InBlock.gif            sb.Append(
"{");
InBlock.gif
InBlock.gif            sb.Append(
"var argument;");
InBlock.gif            sb.Append(
"argument = 'EditStructureData.aspx' + '?StructureUID=' + arg;");
InBlock.gif
InBlock.gif            sb.AppendFormat(
"var dialog = 'dialogWidth={0}px;' + 'dialogHeight={1}px;' + 'center=yes;status=no';", width, height);
InBlock.gif            sb.Append(
"var retValue=window.showModalDialog('Frame.htm',argument,dialog);");
InBlock.gif
InBlock.gif            sb.Append(
"if(retValue==1)");
InBlock.gif            sb.Append(
"top.location.href=top.location.href;");
InBlock.gif            sb.Append(
"}");
InBlock.gif            sb.Append(
"</script>");
ExpandedBlockEnd.gif        }
函数的作用是生成打开模态窗口的JS代码,可以指定窗口的宽度和高度,接收模态窗口关闭后传回的数据。
另处,在发生点击事件的控件处要注册些脚本。如下:
None.gifLinkButton lbnName = e.Item.FindControl("lbnName"as LinkButton;
None.giflbnName.Text 
= dataItem.Name;
None.gif
if(!Page.IsClientScriptBlockRegistered("EditStructureData"))
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    Page.RegisterClientScriptBlock(
"EditStructureData"this.GetOpenModalDialogScript(300,300));
InBlock.gif
InBlock.giflbnName.Attributes.Add(
"onclick",
InBlock.gif    
string.Format("EditStructure('{0}');return false;", dataItem.StructureUID.ToString()));
注意这里传递了一个StructureUID参数,用于在模态窗口中接收这个参数,然后根据参数提取数。

3、在模态窗口中进行数据处理。
在模态窗口的后台代码中添加如下函数:
None.gif        private void EndModalDialog()
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif            
this.EndModalDialog(true);
ExpandedBlockEnd.gif        }

None.gif        
private void EndModalDialog(bool refurbish)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif            
//返回值为1表示成功,top.close()表示把Frame.htm关闭
InBlock.gif
            string script = string.Format("<script language=\'Javascript\'>window.returnValue={0};top.close();</script>", refurbish ? 1 : 0);
InBlock.gif
InBlock.gif            Page.Response.Write(script);
InBlock.gif            Page.Response.End();
ExpandedBlockEnd.gif        }

函数可以指定是否刷新父窗口,在编辑完数据和取消编辑处进行调用。

转载于:https://www.cnblogs.com/BillChen/archive/2005/09/08/232275.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值