栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > asp

ASP.NET中使用IFRAME建立类Modal窗口

asp 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ASP.NET中使用IFRAME建立类Modal窗口

    我们经常要在程序的人机交互中用到模态窗口,但在B/S开发中,这一切变得不容易了,虽然也可以用window.showModalDialog函数实现(见http://dotnet.aspx.cc/ShowDetail.aspx?id=49ML4AO8-5PB3-4KNY-NJZD-LJOIOXV4M1X4),但多数用起来麻烦,还要为了回传值用frameset建立2个无用的窗口。不爽!

    我发现可以尝试在初始页面中嵌入一个Iframe,然后用Iframe来显示一个页面,并将Iframe设定为按绝对位置摆放,Z-Index设置为最高的9999,这样就可以将这个页面覆盖在初始界面上,当需要显示模态窗口时,就显示这个Iframe,可以将Iframe的尺寸扩大到能覆盖住初始窗口,也可以盖住关键项,目的就是不让后面的窗口有什么变化的可能。在Iframe显示的窗口需要关闭时只要对它的parent的Iframe隐藏就可以了。实际试验时发现Iframe的diaplay不能在子窗口被改变,所以,我们还需要将Iframe放到一个DIV中,控制DIV的显示就可以控制窗口的出现或隐藏。但为什么不直接用DIV来显示窗口呢,原因有两个:1.DIV不能遮挡它后面的Dropdownlist控件,而Iframe能。2.不容易将窗口内的内容放置到一个单独的网页中,复用性差。

以下是代码,显示隐藏使用了客户端和服务端代码两种写法:

WebForm1.aspx

 <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WSGUI1.WebForm1" %>


 
  WebForm1
 
 
 
 
 
 
 
 
 

 

WebForm1.aspx.cs

....

 public class WebForm1 : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.DropDownList DropDownList1;
  protected System.Web.UI.HtmlControls.HtmlGenericControl Iframe1;
  protected System.Web.UI.WebControls.Button Button2;

  private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此处放置用户代码以初始化页面
   if(!IsPostBack)
   {

   }
  }
  public static void Createscript(System.Web.UI.Page mypage,string strscript,string ID)
  {
   string strscript="";
   if(!mypage.IsStartupscriptRegistered(ID))
    mypage.RegisterStartupscript(ID, strscript);
  }
  private void Button2_Click(object sender, System.EventArgs e)
  {
   Iframe1.Attributes.Add("src","WebForm2.aspx?NAME='中国'");
   Createscript(Page,"ShowLayer();","SHOW");
  }
 }

 


WebForm2.aspx

 <%@ Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false" Inherits="WSGUI1.WebForm2" %>


 
  WebForm2
 
 
 
 
 
 
 
 
 

 

 

WebFom2.aspx.cs

 namespace WSGUI1
{
 ///


 /// WebForm2 的摘要说明。
 ///

 public class WebForm2 : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.Button Button1;

  private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此处放置用户代码以初始化页面
   if(!IsPostBack)
   {
    Button1.Attributes.Add("onclick","hide()");
   }
  }

 }

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/59891.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号