ASP.NET中使用IFRAME建立类Modal窗口
点击次数:15 次 发布日期:2008-11-26 14:23:19 作者:源代码网
|
源代码网推荐 源代码网推荐 我发现可以尝试在初始页面中嵌入一个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" %> 源代码网推荐 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > 源代码网推荐 <HTML> 源代码网推荐 <HEAD> 源代码网推荐 <title>WebForm1</title> 源代码网推荐 <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"> 源代码网推荐 <meta name="CODE_LANGUAGE" Content="C#"> 源代码网推荐 <meta name="vs_defaultClientScript" content="JavaScript"> 源代码网推荐 <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> 源代码网推荐 <script language="javascript"> 源代码网推荐 function ShowLayer() 源代码网推荐 { 源代码网推荐 document.all.MyFormLayer.style.display=""; 源代码网推荐 return false; 源代码网推荐 } 源代码网推荐 function SetURL(url) 源代码网推荐 { 源代码网推荐 document.all.IFRAME1.src=url; 源代码网推荐 } 源代码网推荐 </script> 源代码网推荐 </HEAD> 源代码网推荐 <body MS_POSITIONING="GridLayout"> 源代码网推荐 <form id="Form1" method="post" runat="server"> 源代码网推荐 <FONT face="宋体"> 源代码网推荐 <asp:DropDownList id="DropDownList1" style="Z-INDEX: 101; LEFT: 40px; POSITION: absolute; TOP: 208px" 源代码网推荐 runat="server" Width="184px"> 源代码网推荐 <asp:ListItem Value="TEST1">q</asp:ListItem> 源代码网推荐 <asp:ListItem Value="TEST2">w</asp:ListItem> 源代码网推荐 <asp:ListItem Value="TEST3">e</asp:ListItem> 源代码网推荐 <asp:ListItem Value="TEST4">r</asp:ListItem> 源代码网推荐 </asp:DropDownList></FONT> <input type="button" name="MyButton" value="TEST" id="MyButton" onclick="ShowLayer();SetURL("WebForm2.aspx")" style="Z-INDEX: 102; LEFT: 360px; POSITION: absolute; TOP: 336px"> 源代码网推荐 <div id="MyFormLayer" style="DISPLAY: none;Z-INDEX: 103;LEFT: 16px;WIDTH: 408px;POSITION: absolute;TOP: 24px;HEIGHT: 304px"> 源代码网推荐 <iframe scrolling="no" frameborder="0" width="100%" height="100%" id="IFRAME1" runat="server"> 源代码网推荐 </iframe> 源代码网推荐 </div> 源代码网推荐 <asp:Button id="Button2" style="Z-INDEX: 104; LEFT: 256px; POSITION: absolute; TOP: 336px" runat="server" 源代码网推荐 Text="ASPXTest"></asp:Button> 源代码网推荐 </form> 源代码网推荐 </body> 源代码网推荐 </HTML> 源代码网推荐 源代码网推荐 源代码网推荐 源代码网推荐 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="<script language="javascript">"; 源代码网推荐 strscript += strScript; 源代码网推荐 strscript += "</script>"; 源代码网推荐 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" %> 源代码网推荐 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > 源代码网推荐 <HTML> 源代码网推荐 <HEAD> 源代码网推荐 <title>WebForm2</title> 源代码网推荐 <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"> 源代码网推荐 <meta name="CODE_LANGUAGE" Content="C#"> 源代码网推荐 <meta name="vs_defaultClientScript" content="JavaScript"> 源代码网推荐 <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> 源代码网推荐 <script language="javascript"> 源代码网推荐 function hide() 源代码网推荐 { 源代码网推荐 parent.MyFormLayer.style.display = "none"; 源代码网推荐 } 源代码网推荐 </script> 源代码网推荐 </HEAD> 源代码网推荐 <body MS_POSITIONING="GridLayout"> 源代码网推荐 <form id="Form2" method="post" runat="server"> 源代码网推荐 <table border="0" width="100%" cellspacing="0" cellpadding="0" bgcolor="#6887bb" height="100%" 源代码网推荐 id="table1" style="BORDER-TOP-STYLE: outset; BORDER-RIGHT-STYLE: outset; BORDER-LEFT-STYLE: outset; BORDER-BOTTOM-STYLE: outset"> 源代码网推荐 <tr> 源代码网推荐 <td> 源代码网推荐 </td> 源代码网推荐 <td> 源代码网推荐 </td> 源代码网推荐 <td> 源代码网推荐 </td> 源代码网推荐 </tr> 源代码网推荐 <tr> 源代码网推荐 <td> 源代码网推荐 </td> 源代码网推荐 <td> 源代码网推荐 <p align="center"><font color="#ffffff">模仿模态窗口效果</font></p> 源代码网推荐 <p align="center"><input type="button" onclick="hide()" style="WIDTH: 80px" value="点击关闭"> 源代码网推荐 <asp:Button id="Button1" runat="server" Text="ASPXTest"></asp:Button></p> 源代码网推荐 </td> 源代码网推荐 <td> 源代码网推荐 </td> 源代码网推荐 </tr> 源代码网推荐 <tr> 源代码网推荐 <td> 源代码网推荐 </td> 源代码网推荐 <td> 源代码网推荐 </td> 源代码网推荐 <td> 源代码网推荐 </td> 源代码网推荐 </tr> 源代码网推荐 </table> 源代码网推荐 </form> 源代码网推荐 </body> 源代码网推荐 </HTML> 源代码网推荐 源代码网推荐 源代码网推荐 源代码网推荐 源代码网推荐 WebFom2.aspx.cs 源代码网推荐 源代码网推荐 namespace WSGUI1 源代码网推荐 { 源代码网推荐 /// <summary> 源代码网推荐 /// WebForm2 的摘要说明。 源代码网推荐 /// </summary> 源代码网推荐 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.ASPCOOL.COM)。 源代码网推荐 源代码网供稿. |
